Reputation: 413
Incrementing particular column in the jqgrid after the service call ,then i am doing automatic sorting using sortable:true,sortorder:asc,sorttype:int
.
When i am sorting, the value in the column is not restored it is vanished and then the grid is sorted .can anybody help me in this situation ,so that i can restore my value even after sorting .
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;
}
But after automatic sorting in the grid the value is not retained.Pls provide me a solution
Upvotes: 3
Views: 1009
Reputation: 146
change the id column to
{ name :'id', index :'id', width :30, align :'left', sortable :true, formatter: incrementingValue }
then add a function after the grid code to handle the increment
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;
}
};
Upvotes: 1