jquery - How to get third row value in jqgrid calculated based on other two column value -
i have there column in jqgrid 2 vales getting json third column have calculate value other 2 , show how can
jquery("#vehicleresultgrid").jqgrid({ data : jsontext, datatype : 'local', rownum : 20000, width : '100%', height : 'auto', colnames : [ 'fin', 'vin','balnce' ], colmodel : [{ name : 'value1', sortable:false, width : 190, classes: "col1" },{ name : 'value2', sortable:false, width : 190 },{ name : 'blance', formatter: calculatedformatfunction }] }); function calculatedformatfunction(cellval, opts, rowobject, action) { return rowobject[0]*rowobject[1]; } i have try code.
if need implement filling of third blance column on client side have 2 main implementation ways:
- usage of custom formatter
- usage of
beforeprocessingcallback.
the second way better because can use predefined formatter calculated column. example can still use formatter: "interger" column blance
in case of usage datatype: 'local' problem of filling third column blance trivial. has input data (variable jsontext in original code) array of items. example has input data as
var myorgdata = [ {value1: 2, value2: 3}, {value1: 5, value2: 7} ]; so can add blance property items in input array:
var l = myorgdata.length, i, item; (i = 0; < l; i++) { item = myorgdata[i]; item.blance = item.value1 * item.value2; // or if values strings // item.blance = parseint(item.value1, 10) * parseint(item.value2, 10); } in way solve problem easy , can use formatter blance column. example can defined blance column like
{name: "blance", formatter: "integer", sorttype: "integer"} if use custom formatter instead
{name: "blance", sorttype: "integer", formatter: function (cellvalue, option, rowobject) { return parseint(rowobject.value1, 10) * parseint(rowobject.value2, 10); }} you use unchanged input data, advantages of predefined formatter can't use or have call original formatters manually make code more complex , less readable.
if have datatype: "json" or datatype: "xml" usage of beforeprocessing callback close simple modification of input data described above. callback beforeprocessing receive data returned server object , callback can modify it. 1 can add additional property in same way.
Comments
Post a Comment