0

i have a calculated field Total which is a sum of amount + tax columns.

i am trying to display calculated field's value in footer in jqgrid, it is not coming properly, currently i am getting Nan in the footer. and also when either amount or tax column has a blank cell i am getting NaN. this is what i have tried, demo link http://jsfiddle.net/vwdxs9vb/2/

please help.

davidb
  • 263
  • 5
  • 10
  • 23

1 Answers1

1

It seems to me, that the main problem is that your origin data contains items with tax:"". parseInt("", 10) is NaN. You should use, for example,

tax = parseInt(rowObject.tax || 0, 10);

instead. See http://jsfiddle.net/OlegKi/vwdxs9vb/4/

Oleg
  • 220,925
  • 34
  • 403
  • 798
  • thank you so much sir, could you please advise on how to to get the cell value wherever the grouping total rows are showing zero for the calculated column. – davidb Oct 20 '17 at 19:07
  • @davidb: You are welcome! Sorry, but I don't understand your last question. The value of which cell you need to get? Additionally it's unclear for me which `datatype` you use in your real program. Mostly it's better to **set** `total` property (on the client side) *before* creating the grid. You need just make one simple loop over input data. Then you will have very simple code and no problems. The usage of `formatter` isn't the best way too. One can use `cellattr` to change background the cell holding `formatter: "number"`. See [here](https://stackoverflow.com/a/12180842/315935) an example. – Oleg Oct 20 '17 at 19:17
  • thank you sir, actually the result of grouping is showing zero for the calculated field, for amount and tax column the grouping result is fine, but for the Total column it is showing zero. http://jsfiddle.net/OlegKi/vwdxs9vb/4/ – davidb Oct 20 '17 at 19:39
  • @davidb: Calculating summary is more difficult. First of all, you have to use `summaryType` defined as function. Seconds, you have to change the code of formatter because it will be called for the grouping summary too. In the case the `callvalue` parameter will be the calculated sum and `options.rowId` will be empty string. See [my old answer](https://stackoverflow.com/a/7622718/315935) for details. You will get the code like http://jsfiddle.net/OlegKi/vwdxs9vb/5/. Additionally I'd recommend you to upgrade retro version 4.6 to [free jqGrid](https://github.com/free-jqgrid/jqGrid) 4.15.1. – Oleg Oct 20 '17 at 20:55
  • thank you so much sir, I got an idea from your answer. – davidb Oct 21 '17 at 06:50
  • Sir,could you please help this https://stackoverflow.com/questions/46939695/jqgrid-validation-on-selecting-dropdown – davidb Oct 25 '17 at 18:36