Background: Our company selected a workflow tool that has some "interersting" UI restrictions. jqGrid has been identified as one of best ways to overcome these restrictions. Consequently, the answers to this question need to be restricted to functionlity available within the jqGrid space. It pains me to pose this question and I know you will tempted to go down a million other paths - most that we have already traveled before. :(
Question: Can jqGrid populate a column as a result of performing math on two other columns. The source of those two columns is in our control so we can "guarantee" that numeric data will be returned. Also, the result is something that we simplay want to display on demand but not store yet. On the example below, is there a function that allow the 'total' column to be populated from the following calculation: 'amount' * 'tax'
Example jqGrid javascript:
jQuery("#list3").jqGrid({
url:'server.php?q=2',
datatype: "json",
col开发者_如何学GoNames:['Inv No','Date', 'Client', 'Amount','Tax','Total','Notes'],
colModel:[
{name:'id',index:'id', width:60, sorttype:"int"},
{name:'invdate',index:'invdate', width:90, sorttype:"date"},
{name:'name',index:'name', width:100},
{name:'amount',index:'amount', width:80, align:"right",sorttype:"float"},
{name:'tax',index:'tax', width:80, align:"right",sorttype:"float"},
{name:'total',index:'total', width:80,align:"right",sorttype:"float"},
{name:'note',index:'note', width:150, sortable:false}
],
rowNum:20,
rowList:[10,20,30],
pager: '#pager3',
sortname: 'id',
viewrecords: true,
sortorder: "desc",
loadonce: true,
caption: "Load Once Example"
});
Do you want this computation to be performed when the grid is first loaded? If so, you could specify a function as the data type. For example:
datatype: function(postdata) {
jQuery.ajax({
url: 'example.php',
data:postdata,
dataType:"xml",
complete: function(xmldata,stat){
if(stat=="success") {
var thegrid = jQuery("#list3")[0];
// Loop over the XML one row at a time here,
// Calculate total, and call addRowData to add it to the jqGrid
}
}
});
},
Alternatively, if you are editing the data and would like to perform the calculation when the edit is complete, could you please give more information such as the type of editing you are performing (inline, form, etc)?
精彩评论