This is a migrated thread and some comments may be shown as answers.

Summation with Multi-row select

1 Answer 13 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Support
Top achievements
Rank 1
Support asked on 10 Aug 2013, 09:04 AM
Hi there,

I have a grid which contains "Quantity" and "Amount" columns. When the user selects multiple rows from the grid, they can then click a "Sum" button which will calculate the Total Quantity and Total Amount based on the current selected rows. How can I achieve this?

1 Answer, 1 is accepted

Sort by
0
Dimiter Madjarov
Telerik team
answered on 13 Aug 2013, 11:36 AM
Hello,

Here is a sample implementation of the required calculation.
E.g.
<button id="calculate">Calculate</button>
<script>
    $("#calculate").click(function () {
        var grid = $("#Grid").data("kendoGrid");
        var selection = grid.select();
 
        var total = 0;
        for (var i = 0; i < selection.length; i++) {
            var dataItem = grid.dataItem(selection[i]);
            total += dataItem["Amount"];
        }
    });
</script>

For each row of the selection, I am retrieving the model via the dataItem method of the Grid, accessing the Amount property of the model and adding it to the total amount.

I hope that this approach will work for you. I wish you a great day!

 

Regards,
Dimiter Madjarov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Support
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
Share this question
or