2016-04-14 126 views
0

我正在使用Gijgo網格來管理表格的數據。如何在Gijgo Grid中設置不同的背景色到行?

我會設置不同行的背景顏色。顏色在模型中。

查看

 grid = $("#grid").grid({ 
     dataSource: { url: '@Url.Action("Method", "MyController")', success: onSuccessFunc }, 
     dataKey: "Id", 
     uiLibrary: "bootstrap", 
     columns: 
     [ 
      { field: "Id", sortable: false, hidden: true }, 
      { field: "Name", sortable: false, hidden: true }, 
      { field: "Description", title: "Tipologia", sortable: false, width: "70%" }, 
      { field: "Value1", title: "Value 1", align: 'center', sortable: false }, 
      { field: "Value2", title: "Value 2", align: 'center', sortable: false }, 
      { field: "Edit", title: "", width: 34, type: "icon", icon: "glyphicon-pencil", tooltip: "Edit", events: { "click": Edit } } 
     ] 
    }); 

視圖模型

public class ViewModel 
{ 
    public int Id { get; set; } 
    public string Name { get; set; } 
    public string Description { get; set; } 
    public double? Value1 { get; set; } 
    public double? Value2 { get; set; } 
    public string Group { get; set; } 
    public string BackGroudColor { get; set; } 
} 

我該怎麼做才能綁定網格的行的屬性的bac​​kgroundColor到BACKGROUNDCOLOR模型的財產?

非常感謝。

查爾斯

回答

2

最好的辦法是使用gijgo網格的RowDataBound事件。
您可以在http://gijgo.com/Grid/Events/rowDataBound

例閱讀更多關於此事件1:

grid.on('rowDataBound', function (e, $row, id, record) { 
    $row.css('background-color', id%2 === 0 ? '#FFFFFF' : '#CCCCCC'); 
}); 

例2:

grid.on('rowDataBound', function (e, $row, id, record) { 
    if (record.Name === 'something') { 
     $row.css('background-color', '#CCCCCC'); 
    } 
}); 
+0

大阿塔納斯...謝謝您 – Charles