<%= Html.Telerik().Grid(Model)
.Name("Grid")
.ClientEvents(events => events.OnDataBinding("Grid_onDataBinding"))
%>
<script type="text/javascript">
function Grid_onDataBinding(e){
//handling code
}
</script>
我需要更改databind
事件中每列的文字颜色。如何通过Telerik Grid中的JavaScript访问Rowdata
?
答案 0 :(得分:2)
您必须处理绑定行时触发的RowDataBound事件。然后,这将允许您访问行(TR)。
...
.ClientEvents(events => events.OnRowDataBound("Grid_onRowDataBound"))
function Grid_onRowDataBound(e) {
var row = e.row;
var dataItem = e.dataItem;
row.className = "your-class-name";
// Can also use row.cells
// row.cells[1].innerHTML = "<span class='class-name'>" + dataItem.text + "</strong>";
}
样式
tr.your-class-name {
color: red;
}