We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

sum of particular column based on another column while filtering

Here is my code ,

var Value1=0;
var Value2=0;
var obj = $("#Grid").ejGrid("model");

                                for (var i = 0; i < obj.dataSource.length; i++) 
                                    if (obj.dataSource[i].Status == "VIEW") {
                                       Value1 += obj.dataSource[i].Amount;                              
                                    else if (obj.dataSource[i].Status == "NOT VIEW") 
                                          Value2 += obj.dataSource[i].Amount;                            

i want to sum the amount column based on status column value.

but it's not working while filtering. i am also tried in GetFilteredRecords. It doesn't contains the properties to acheive.

can u suggest how to do it?

1 Reply

GV Gowthami V Syncfusion Team June 15, 2015 01:10 PM UTC

Hi Ganga,

Thanks for using Syncfusion products.

We can achieve your requirement by using “predicated” parameter ,in which we can get the predicate of the filtered records in ActionComplete event of the grid.

We can get the filtered data by passing predicate value using where method of the query as follows.


. . . .



<script type="text/javascript">

    var origData, flag=0;

function complete(args)



          origData = this.model.dataSource;


  if (args.requestType == "filtering" && !ej.isNullOrUndefined(args.predicated)) {

            this.model.dataSource = this._dataManager.executeLocal(this.model.query.where(args.predicated)).result;



        else {

            this.model.dataSource = origData; //Retaining the original data while clear the filter




Please try the above snippet and let us know if you have any queries.

Gowthami V.

Live Chat Icon For mobile
Up arrow icon