jQuery UI Widgets Forums Grid Sum for a calculated-field

This topic contains 7 replies, has 3 voices, and was last updated by  san1646 9 years, 5 months ago.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
  • Sum for a calculated-field #72961

    san1646
    Participant

    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

    Sum for a calculated-field #72962

    drv232
    Participant

    You can use aggregates: [‘sum’] in

    
    
    {
                                text: 'Calc Hrs(G)',
                                datafield: 'calcWorkTime',
                                editable: false,
                                width: 100,
                                cellsalign: 'center',aggregates: ['sum']
            }
    
    Sum for a calculated-field #72964

    san1646
    Participant

    I tried that, but it is not working.

    Sum for a calculated-field #72968

    Dimitar
    Participant

    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,
    Dimitar

    jQWidgets team
    http://www.jqwidgets.com/

    Sum for a calculated-field #73014

    san1646
    Participant

    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>”;

    Sum for a calculated-field #73031

    san1646
    Participant

    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
    Sanket

    Sum for a calculated-field #73061

    Dimitar
    Participant

    Hi Sanket,

    1. 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>";
    2. 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,
    Dimitar

    jQWidgets team
    http://www.jqwidgets.com/

    Sum for a calculated-field #73164

    san1646
    Participant

    Thanks, this seems to solve my issue.

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.