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.

Summary format

Thread ID:

Created:

Updated:

Platform:

Replies:

121721 Jan 19,2016 10:19 AM Jan 20,2016 01:12 AM ASP.NET MVC 1
loading
Tags: Grid
Mika Kahilainen
Asked On January 19, 2016 10:19 AM

Hi

Question is related to this sample: https://www.syncfusion.com/kb/4107/how-to-bind-timespan-value-to-grid-column

If Summary is added for  Worked Hours column, how it can be formatted to keep time format? It will show sum as decimal but I need to convert in into time like 12:23:00.

Mika

Ragavee U S [Syncfusion]
Replied On January 20, 2016 01:12 AM

Hi Mika,

Since WorkedHours column is a complex object using summary will provide incorrect result and so we can use custom summary option to show correct values. Please refer the below code example.


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

         . . . .

                .SummaryRow(row => {

                    row.SummaryColumns(col => {

                        col.SummaryType(SummaryType.Custom).CustomSummaryValue("TimeSpanCounter").Format("{0:D2}").Add();

                    }).Add();

                })
        )
       

<script type="text/javascript">

          function TimeSpanCounter(summary, data) {


            data = ej.select(data, ["WorkedHours"]);


            //Helper to calulate the total time

            var getter = function (prop, divisor, prev) {


                var f = ej.select(data, [prop]), sum = 0 + (prev || 0);


                sum += ej.sum(f);


                if (prop == "Hours")

                    return sum;


                return {

                    prev: ~~(sum / divisor),

                    org: sum % divisor

                };

            };


            var sec = getter("Seconds", 60), min = getter("Minutes", 60, sec.prev), hours = getter("Hours");


            return this.formatting(summary.format, hours) + " : " + this.formatting(summary.format, min.org) + " : " + this.formatting(summary.format, sec.org);

        }


    </script>


The formatting of the result is done with the formatting method of the Grid. The custom summary method will be provided with two arguments i.e., summary details and the current view data of the grid.

For your convenience, we have created a sample with the above solution, which can be downloaded from the below location.

Sample Link: http://www.syncfusion.com/downloads/support/forum/121721/ze/Sample1193677306

Regards,
Ragavee U S.

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.

;