jQuery UI Widgets › Forums › Grid › Sum for a calculated-field
Tagged: aggregates, angular grid, calculated, cellsrenderer, column, computed column, grid, jquery grid, jqxgrid, setcellvalue, sum
This topic contains 7 replies, has 3 voices, and was last updated by san1646 9 years, 5 months ago.
-
Author
-
Hi,
I am trying to get the sum of a calculated field in a grid. I have created a demo.Demo here: https://www.jseditor.io/?key=calculated-field-sum
When I use the method ‘getcolumnaggregateddata’ to get the sum for the field ‘calcWorkTime’, I get no result.
Is it possible, and if yes, is there any other way?
Thanks
You can use aggregates: [‘sum’] in
{ text: 'Calc Hrs(G)', datafield: 'calcWorkTime', editable: false, width: 100, cellsalign: 'center',aggregates: ['sum'] }
I tried that, but it is not working.
Hello,
Computed (calculated) columns do not have actual cell values, only what is displayed by cellsrenderer. That is why aggregates cannot be applied to them. Our suggestion is to set the computed column cell values with setcellvalue, e.g.: https://www.jseditor.io/?key=calculated-field-sum-fixed.
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/Thank you very much Dimitar!
I tried it and was able to get it working.Can you also tell me how I can add CSS to the computed column using this method (setcellvalue).
Earlier I used this:
return “<div style=’margin: 4px; background-color: #FFFF00;’ class=’jqx-center-align’ >” + dataAdapter.formatNumber(total, “f2”) + “</div>”;Hi Dimitar,
After doing the changes you said, I did a round of testing and realized this has created a different issue for me.
I am calculating value using other fields and setting it in the cell for ‘Calc Hrs’ (using setcellvalue).
But since this is being done in the ready function for the grid, any changes by the user after grid is loaded are not reflected.The only way I know to achieve instant reflection in the computed value is via cellsrenderer. But I tried using setcellvalue in there, but the grid does not load.
Thank you
SanketHi Sanket,
- Even when using setcellvalue, you can use cellsrenderer for cell styling:
return "<div style='margin: 4px; background-color: #FFFF00;' class='jqx-center-align' >" + value + "</div>";
- Update the computed column’s cell when a cell of one of the other columns is edited again with setcellvalue. This can be done on the event cellendedit (example).
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/Thanks, this seems to solve my issue.
- Even when using setcellvalue, you can use cellsrenderer for cell styling:
-
AuthorPosts
You must be logged in to reply to this topic.