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

My summaryRows is always empty (zero)

I don't know why, the main summary on ejGrid is always empty.


HTML
<div id="Grid" data-bind="ejGrid: {
     dataSource: dataSource,
     summaryRows: summaryRows,
     showSummary: true,
     allowGrouping: true,
     allowPaging: false,
     pageSettings: { pageSize: 5 },                     
     locale: 'pt-BR',
    groupSettings: { showUngroupButton: false, groupedColumns: ['TypeName'] },
    columns: column,
     toolbarSettings: {
        showToolbar: false,
        toolbarItems: [ej.Grid.ToolBarItems.PrintGrid, ej.Grid.ToolBarItems.ExcelExport]
     },
}">


SCRIPT
<script type="text/javascript">
        $(function () {

            window.baseView = {
                dataSource: ej.DataManager({ url: '@Url.Action("KODataSource")', adaptor: "UrlAdaptor" }),
                column: [
                          { field: "TypeName", isPrimaryKey: true, headerText: "Tipo" },
                          { field: "CategoryName", headerText: "Categoria" },
                          { field: "Price", headerText: "Valor (R$)", format: "{0:n}", textAlign: ej.TextAlign.Right }
                ],
                summaryRows: [
                          {
                              showCaptionSummary: true,
                              title: "Total",
                              summaryColumns: [{
                                  summaryType: ej.Grid.SummaryType.Sum,
                                  displayColumn: "Price",
                                  dataMember: "Price",
                                  format: "{0:n}"
                              }]
                          }
                ]
            };

            ko.applyBindings(baseView);

});

    </script>


CONTROLLER
[AcceptVerbs(HttpVerbs.Post)]
        public ActionResult KODataSource(DataManager clsDataManager)
        {
            DateTime dteInitialDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
            DateTime dteEndDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month));

            if (clsDataManager.Where != null && clsDataManager.Where.Count > 0)
            {
                WhereFilter whereInitialDate = clsDataManager.Where.Where(item => item.Field == "InitialDate").FirstOrDefault();
                WhereFilter whereEndDate = clsDataManager.Where.Where(item => item.Field == "EndDate").FirstOrDefault();

                if (whereInitialDate != null && whereEndDate != null &&
                    whereInitialDate.value != null && whereEndDate.value != null)
                {
                    dteInitialDate = DateTime.Parse(whereInitialDate.value.ToString());
                    dteEndDate = DateTime.Parse(whereEndDate.value.ToString());
                }
            }

            List<Bill> clsBills = BillBusiness.GetAllFilterReports(dteInitialDate, dteEndDate).ToList();

            CashFlowModel clsModel = new CashFlowModel()
            {
                Items = Mapper.Map<List<Bill>, List<CashFlowItemModel>>(clsBills)
            };

            BaseResult<CashFlowItemModel> clsData = new BaseResult<CashFlowItemModel>();
            clsData.Result = clsModel.Items.GroupBy(item => new { item.CategoryName, item.TypeName })
                                        .Select(item =>
                                        new CashFlowItemModel()
                                        {
                                            CategoryName = item.Key.CategoryName,
                                            TypeName = item.Key.TypeName,
                                            Price = item.Sum(sum => sum.Price)
                                        }).AsQueryable();

            ResultModel result = new ResultModel();

            result.result = clsData.Result;
            result.count = clsData.Result.Count();

            return Json(result, "application/json", Encoding.Default, JsonRequestBehavior.AllowGet);
        }



1 - Can you help me with this problem ?

2 - Another question, Can I get my Data that binding on ejGrid? Maybe I use in other places.

Thank you.

Attachment: problem_a0e1041a.zip

3 Replies

SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team September 15, 2015 09:02 AM UTC

Hi Cristiano,

Thanks for contacting Syncfusion Support.

Query1: the main summary on ejGrid is always empty.

Summary Rows has not been handled in the server-side in the given code example. While using remote data, Summary Row must be handled by returning summary column and their respective datasource into the aggregate key, as shown in the below example.

[View]

<div id="Grid" data-bind="ejGrid: {dataSource: dataSource, columns: col,showSummary: true,allowGrouping:true,summaryRows:summaryRows}"></div>

<script src="~/Scripts/jsondata.min.js"></script>

<script type="text/javascript">

        $(function () {

            window.orderView = {

                dataSource: ej.DataManager({ url: '/Grid/DataSource', adaptor: "UrlAdaptor" }),

                col: [{ field: 'OrderID', headertext: 'Order ID', width: '75', textalign: ej.TextAlign.Right },

           . . .

               ],


                summaryRows: [{ title: "Sum", summaryColumns: [{ summaryType: ej.Grid.SummaryType.Sum, displayColumn: "Freight", dataMember: "Freight", format: "{0:C2}" }],

                    showTotalSummary: true

                }],

            };

            ko.applyBindings(orderView);

        });


</script>




[Ctrl]

public partial class GridController: Controller

    {

        . . .

       public ActionResult DataSource(DataManager dm)

        {


            IEnumerable DataSource = OrderRepository.GetAllRecords();

            DataOperations ds = new DataOperations();

            DataResult result = new DataResult();

            List<string> str = new List<string>();

            if (dm.Aggregates != null)

            {

                for (var i = 0; i < dm.Aggregates.Count; i++)

                    str.Add(dm.Aggregates[i].Field);

                result.aggregate = ds.PerformSelect(DataSource, str);

            }

           DataSource = ds.PerformSkip(DataSource, dm.Skip);

            result.result = ds.PerformTake(DataSource, dm.Take);

            result.count = DataSource.AsQueryable().Count();

            return Json(result, JsonRequestBehavior.AllowGet);

        }

      . . .
   }



Please refer following sample and output
Sample:
http://www.syncfusion.com/downloads/support/forum/120254/ze/MvcApplication4-1802747650

OutPut:



Query2:  Can I get my Data that binding on ejGrid?

Create a Grid instance and retrieve the DataSource instance via model of Grid. We can use currentViewData from model, to retrieve the data bound currently(CurrentPage’s data) to the grid.

var obj = $("#Grid").ejGrid("instance")

obj.model.dataSource; // instance of dataManager

obj.model.currentViewData; //retreives the currentPage's data alone



Regards,
Seeni Sakthi Kumar S.


CS Cristiano Souza Silva September 18, 2015 07:24 PM UTC

Works for me.

Thank you.


SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team September 21, 2015 06:09 AM UTC

Hi Cristiano,

Thanks for the update.

We are glad to know that our solution helped you achieve your requirement. Please get back to us if you need any further assistance.

Regards,
Seeni Sakthi Kumar S.

Loader.
Live Chat Icon For mobile
Up arrow icon