easyui DataGrid checkbox 根据后台传递过来的数据进行勾选

 
[javascript]  view plain  copy
  1. function loadMessage() {  
  2.     $('#pressure').datagrid({  
  3.         height: 500,  
  4.         url: '/Home/RealtimeData',  
  5.         method: 'POST',  
  6.         //queryParams: { 'id': OBJECTID },  
  7.         idField: 'ID',  
  8.         striped: true,  
  9.         fitColumns: true,  
  10.         singleSelect: false,  
  11.         rownumbers: true,  
  12.         pagination: false,  
  13.         nowrap: false,  
  14.         pageSize: 10,  
  15.         pageList: [10, 20, 50, 100, 150, 200],  
  16.         showFooter: true,  
  17.         columns: [[  
  18.             { field: 'ck', checkbox: true },  
  19.             { field: 'ElementId', title: 'ElementId', width: 180, align: 'left' },  
  20.             { field: 'Label', title: 'Label', width: 180, align: 'left' },  
  21.             { field: 'Meter_Name', title: 'Meter_Name', width: 180, align: 'left' },  
  22.             { field: 'Station_Un', title: 'Station_Un', width: 180, align: 'left' },  
  23.             { field: 'MeasureAre', title: 'MeasureAre', width: 180, align: 'left' },  
  24.             { field: 'DistrictAr', title: 'DistrictAr', width: 180, align: 'left' },  
  25.             { field: 'Explain', title: 'Explain', width: 180, align: 'left' }  
  26.         ]],  
  27.         onBeforeLoad: function (param) {  
  28.   
  29.         },  
  30.         onLoadSuccess: function (data) {  
  31.             if (data) {  
  32.                 $.each(data.rows, function (index, item) {  
  33.                     if (item.Display == 1) {  
  34.                         $('#pressure').datagrid('checkRow', index);  
  35.                     }  
  36.                 });  
  37.             }  
  38.         },  
  39.         onLoadError: function () {  
  40.   
  41.         },  
  42.         onClickCell: function (rowIndex, field, value) {  
  43.   
  44.         }  
  45.     });  
  46. }  

在onLoadSuccess 事件中添加循环事件,如果display显示的是一,则将当前那一行设为选中状态。

猜你喜欢

转载自blog.csdn.net/qq_40435659/article/details/79868132