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.
Unfortunately, activation email could not send to your email. Please try again.

how to get the sum for certain column data in treegrid?

Thread ID:

Created:

Updated:

Platform:

Replies:

120786 Oct 14,2015 03:47 PM Oct 16,2015 01:09 AM ASP.NET MVC 3
loading
Tags: TreeGrid
Harry Zheng
Asked On October 14, 2015 03:47 PM

Hi,

In treegrid, I have a column "Percent", in which user can input number. I'd like to calculate the total percent each time user finish entering number.
In that way, I can ensure the total number input for the column will not be greater than 100.
How do I get the total sum for column "Percent"?
Thanks,

Harry

Mahalakshmi Karthikeyan [Syncfusion]
Replied On October 15, 2015 06:13 AM

Hi Harry,

We can get the sum of particular column after the editing with the help of “EndEdit” client side event. Please refer the below code example for details.

@(Html.EJ().TreeGrid("TreeGridContainer")

//…

.Columns(co => {

       //…

       co.Field("PercentDone").HeaderText("Progress").Add();

}).

ClientSideEvents(eve => {

       eve.EndEdit("endedit");

}).

Datasource(ViewBag.dataSource))

<script type = "text/javascript" >

function endedit(args) {

       var percentValue = parseInt(args.data.PercentDone);

       if (args.columnName == "PercentDone") {

              var treeObj = $("#TreeGridContainer").data("ejTreeGrid");

              var records = treeObj.model.flatRecords;

              for (var i = 0; i < records.length; i++) {

                     if (!ej.isNullOrUndefined(records[i].PercentDone) && records[i].index != args.data.index) percentValue += records[i].PercentDone;

              }

              if (percentValue > 100) args.cancel = true

              alert("Total of Percent Column is" + percentValue);

       }

}

</script>

Here we have displayed the sum of percent column in alert box, and cancelled the editing if the entered value makes the sum greater than 100 using “args.cancel=true”.

Can you please share us more details about the percentage value you have considered as 100% to convert the sum value to percentage?

We have also prepared a sample based on this and you can find the sample under the following location.

Sample: http://www.syncfusion.com/downloads/support/directtrac/general/ze/SumThePercentage705145007

Regards,

Mahalakshmi K.


Harry Zheng
Replied On October 15, 2015 02:10 PM

Hi Mahalakshmi,

Thank you for the solution. It's working!
Regards,

Harry

Mahalakshmi Karthikeyan [Syncfusion]
Replied On October 16, 2015 01:09 AM

Hi Harry,

Thanks for the update.

Please let us know if you need further assistance on this.

Regards,

Mahalakshmi K.


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.

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.

;