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.

@(Html.EJ().Grid<object>("FlatGrid")

. . . .

.ClientSideEvents(eve=>{eve.ActionComplete("complete");})

)


<script type="text/javascript">

    var origData, flag=0;

function complete(args)

    {

      if(flag==0)

          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;

            flag++;

        }

        else {

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

        }

       

    }
</script>


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

Regards,
Gowthami V.

Loader.
Live Chat Icon For mobile
Up arrow icon