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. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

sum of particular column based on another column while filtering

Thread ID:

Created:

Updated:

Platform:

Replies:

119386 Jun 13,2015 09:19 AM UTC Jun 15,2015 01:10 PM UTC ASP.NET MVC 1
loading
Tags: Grid
Ganga
Asked On June 13, 2015 09:19 AM UTC


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?





Gowthami V [Syncfusion]
Replied On 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.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;