0

在初始化期间设置 css 属性时,它可以正常工作,从函数启动时,单元格中的颜色和背景也会发生变化。但是当我对列进行排序时,从函数中设置的所有颜色都会消失并返回到正常网格。

<script>
var Mydata =[
  {
    "id":"560058",
    "nm" : "L 41971",
    "temp" : "21.2",
    "ignition" : "off",
    "pos_x" : "55.2024832",
    "pos_y" : "24.9640256",
    "drv" : "",
    "pos_s" : "0",
    "param24" : "0",
    "param240" : "0",
    "pwr_ext" : "12.825"
  },
  {
    "id":"560059",
    "nm" : "L 41972",
    "temp" : "21.2",
    "ignition" : "off",
    "pos_x" : "55.2024832",
    "pos_y" : "24.9640256",
    "drv" : "",
    "pos_s" : "0",
    "param24" : "0",
    "param240" : "0",
    "pwr_ext" : "12.825"
  }
];
var grid = $("#live_view");
grid.jqGrid({
  height: '100%',
  width: '700',
  datatype: "local",
  loadonce: true,
  data : Mydata,
  gridview: true,
  colNames: ['Name', 'Temperature', 'Ignition', 'lat', 'lon', 'Driver', 'Speed', 'param24', 'movement', 'pwr_ext'],
  colModel:[
    {name:'nm',index:'nm'},
    {name:'temp',index:'temp'},
    {name:'ignition',index:'ignition'},
    {name:'pos_x',index:'pos_x'},
    {name:'pos_y',index:'pos_y'},
    {name:'drv',index:'drv'},
    {name:'pos_s',index:'pos_s'},
    {name:'param24',index:'param24'},
    {name:'param240',index:'param240'},
    {name:'pwr_ext',index:'pwr_ext'},
  ],
  rowNum:100,
  rowList:[100,200,300],
  pager: '#pager2',
  sortname: 'param240',
  viewrecords: true,
  sortorder: "desc",
  caption:"Vertex Live View",
  loadComplete: function() {
    grid.jqGrid('setCell',"560058","nm","",color:'red'});
  },
});
$("#live_view").jqGrid('navGrid','#pager2',{edit:false,add:false,del:false});
$("#cc").click(function (){
  $("#live_view").jqGrid('setCell',"560058","nm","",{color:'blue'});
})
</script>
<a href="#" id="cc">Change Colour</a>
4

1 回答 1

0

排序时,它会重新创建 html。jqgrid 都知道,您修改的列在排序后甚至可能在当前页面上不可见。底线,您将需要重新应用颜色。

您可以仔细阅读 jqGrid api,看看它们是否允许从模型数据中设置单元格的颜色。不过我不这么认为。

于 2012-11-25T08:32:34.933 回答