asp.net mvc - Defining inline row style in System.Web.Helpers.WebGrid -
i moving application mvc 3 , try use system.web.helpers.webgrid. html code like:
<table> <tr style="background-color: <%= item.color %>"> </tr> <tr style="background-color: <%= item.color %>"> </tr> <tr style="background-color: <%= item.color %>"> </tr> </table>
there rowstyle
property, allows define css class every row, there different style every row. achieveable easily?
so had finish hack. first, include color part of column. had returned mvchtmlstring
avoid additional encoding:
<% var grid = new webgrid(model); %> <%= grid.gethtml( tablestyle: "table_class", columns: grid.columns( grid.column("importance", ctres.importance, (item) => new mvchtmlstring(html.encode(item.importance) + "<div class='color' style='display: none;'>#" + item.color + "</div>")) ) ) %>
then setting bacground color in $(document).ready()
:
<script type="text/javascript"> $(document).ready( function () { $('.table_class .color').each(function (index, element) { $(element).parent().parent().css('background-color', $(element).html()); }); } ); </script>
Comments
Post a Comment