3

在服务调用后增加 jqgrid 中的特定列,然后我正在使用sortable:true,sortorder:asc,sorttype:int. 当我排序时,列中的值没有恢复,它消失了,然后网格被排序。在这种情况下任何人都可以帮助我,这样即使在排序后我也可以恢复我的值。

here is the code, 

$('#gridValue)
      .jqGrid(
           {

            datastr :parsedObj,
            datatype :'jsonstring',
            height :140,
            width :240,
            colNames : [ "Id","Name","Count" ],
            colModel : [ {
               name :'id',
               index :'id',
               width :30,
               align :'left',
               sortable :true
            }, {
               name :'name',
               index :'name',
               width :30,
               align :'left'
            }, {
               name :'count',
               index :'count',
               width :20,
               align :'left',
               sortable :true
             }],

             rowNum :20,
             sortname : 'id',
             sorttype :'int',
             scroll :true,
             viewrecords :true,
             shrinkToFit :false,
             hoverrows :true,
             cellEdit :true,
             loadonce :true,
             sortorder :'asc',

               jsonReader : {
                   root :'paramValue',
                   repeatitems :false,
                   page : function(parsedObj) {
                   return 1;
                   },
                   total : function(parsedObj) {
                   return 1;
                   },
                   records : function(parsedObj) {
                   }
                   },
               gridComplete : function() {
                   var gridTable = document
                            getElementById("gridValue");
                   var gridTableCount = gridTableCount.rows.length;
                   if (gridTableCount> 1) {
                      for (countId = 1; countId < gridTableCount; countId++) {
   document.getElementById("gridValue").rows[countId].cells[2].innerHTML = '0';                                                                   }
                                                                }
                                                        }
                                        });     
                        $("#gridValue").setGridParam({
                                sortname : 'count',
                                sortorder : 'asc'
                        }).trigger('reloadGrid');
                   }

//After service call i will be calling this function to update value in grid
function incrementingValue(){
     document.getElementById("gridValue").rows[countId].cells[2].innerHTML =1;
}

但是在网格中自动排序后,值不会保留。请给我一个解决方案

4

1 回答 1

1

将 id 列更改为

{名称:'id',索引:'id',宽度:30,对齐:'left',可排序:true,格式化程序:incrementingValue}

然后在网格代码之后添加一个函数来处理增量

var counter; //when calling the service you can increase your value to the counter
function incrementingValue(cellvalue, options, rowObject) {
    //var cellValueInt = parseInt(cellvalue); // this bring the existing cell value
    return counter=1;
    }
}; 
于 2013-01-04T23:23:21.127 回答