If you need implement filling of the third blance column on the client side you have two main implementation ways:
- usage of custom formatter
- usage of
beforeProcessing callback.
The second way is better because you can use some predefined formatter for calculated column. For example you can still use formatter: "interger" for the column blance
In case of usage datatype: 'local' the problem of filling third column blance is really trivial. You has already input data (variable jsonText in your original code) as array of items. For example you has input data as
var myOrgData = [
{value1: 2, value2: 3},
{value1: 5, value2: 7}
];
So you can just add blance property to all items in the input array:
var l = myOrgData.length, i, item;
for (i = 0; i < l; i++) {
item = myOrgData[i];
item.blance = item.value1 * item.value2;
// or if the values could be strings then
// item.blance = parseInt(item.value1, 10) * parseInt(item.value2, 10);
}
In the way you solve the problem very easy and can use any formatter for the blance column. For example you can defined blance column like
{name: "blance", formatter: "integer", sorttype: "integer"}
If you would use custom formatter instead
{name: "blance", sorttype: "integer",
formatter: function (cellValue, option, rowObject) {
return parseInt(rowObject.value1, 10) * parseInt(rowObject.value2, 10);
}}
You could use unchanged input data, but the advantages of predefined formatter you can't use or you would have to call the original formatters manually which make the code more complex and less readable.
If you have datatype: "json" or datatype: "xml" than the usage of beforeProcessing callback is very close to the simple modification of input data described above. The callback beforeProcessing receive the data returned from the server as object and the callback can modify it. One can add additional property in the same way.