jQWidgets Forums

jQuery UI Widgets Forums Grid Grid rowselect and update aggregate based on selections

This topic contains 5 replies, has 4 voices, and was last updated by  Yavor Dashev 3 years, 9 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author

  • dan123
    Participant

    Hi is there a way to update the aggregates while performing rowselect event? I have created a jsfiddle that shows a Price column and right next to is the checkbox column to perform selections. So based on the selected rows, the status bar should update its aggregates based on the selections.

    Here is my jsfiddle:
    http://jsfiddle.net/Ne5a9/77/


    Hristo
    Participant

    Hello dan123,

    Unfortunately, there is no such option.
    I would suggest you bind to rowselect event and with custom logic to get “aggregate” value that will append to some additional container under the Grid.
    Hope this will help.

    Best Regards,
    Hristo Hristov

    jQWidgets team
    http://www.jqwidgets.com


    dan123
    Participant

    Can you show an example please?


    Hristo
    Participant

    Hello dan123,

    I would like to suggest you look at this topic, there you will find out how to get aggregates:
    http://www.jqwidgets.com/community/topic/get-the-value-of-aggregates-in-a-column/
    Other things are customizations and you could add in the desired way.

    Best Regards,
    Hristo Hristov

    jQWidgets team
    http://www.jqwidgets.com


    mpintoz
    Participant

    Hello friend I had a similar problem, I wanted a checkbox column if it was true to take the value of another column to add a total here I leave my code:

    COLUMN SUM()
    { text: ‘Impuesto’, datafield: ‘Impuesto’, width: 110, align: ‘center’, cellsalign: ‘center’, editable: false , //aggregates: [‘sum’] },
    aggregates: [{ ‘<b>Total: </b>’:
    function (aggregatedValue, currentValue, column, record) {
    var total = 0;
    if(record[‘Aplicar’] == 1){
    total = parseFloat(record[‘Impuesto’]);
    }
    return aggregatedValue + total;
    }
    }]
    },

    COLUMN CONDITION:
    { text: ‘Aplicar’, datafield: ‘Aplicar’, width: 70, columntype: ‘checkbox’, align: ‘center’, cellsalign: ‘center’, cellsrenderer: columncheckboxRenderer }

    var columncheckboxRenderer = function (value) {
    $(“#jqxgridImpuestos”).jqxGrid(‘endupdate’);
    }


    Yavor Dashev
    Participant

    Hi mpintoz,

    As stated above the jqxGrid doesn’t support this king of functionality, but I have create a workaround for this use case.

    The code example: http://jsfiddle.net/szjfbt3h/4/

    And the more important part is this code snippet:

                let summaryData = $("#grid").jqxGrid('getcolumnaggregateddata','price', ['sum']);
    
                $("#grid").on('rowselect', function (event) 
                    {
                        // event arguments.
                        let args = event.args,
                            rowData = args.row.quantity,
                            statusbarGrid = document.getElementById('statusrowgrid'),
                            newSum = Math.floor( summaryData.sum + rowData );
    
                        summaryData.sum = newSum;
    
                        statusbarGrid.lastElementChild.firstChild.innerText="Sum: $"+ newSum +"";
                    });
            });

    We get the summary data with the getcolumnaggregateddata method and when a row is selected we add the value of one of the cells in this row to the summary data.

    Let me know if that works for you!

    Please, do not hesitate to contact us if you have any additional questions.

    Best Regards,
    Yavor Dashev
    jQWidgets team
    https://www.jqwidgets.com

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

You must be logged in to reply to this topic.