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

Grid Summary Total In Batch Edit Mode, Type Ahead, Appending To Filter

I have several questions regarding the Grid control.

1) I have a grid in batch edit mode which allows filtering and grouping. The summary total at the bottom of the grid shows incorrectly as "0" all the time - however, the summary totals for groups appears to work correctly. How can I get the summary to show:

@(Html.EJ().Grid<ReallocateCashRow>("Grid")
      // Note: the summary totals at the bottom of the grid do work if I pass in the data through the model
      //.Datasource(Model)    
      .Datasource(ds => ds.URL(@Url.Action("BatchDataSource","AccountSettings")).BatchURL(@Url.Action("BatchUpdate","AccountSettings")).Adaptor(AdaptorType.UrlAdaptor))   
      .EditSettings(edit => { edit.AllowEditing().EditMode(EditMode.Batch); })
      .AllowFiltering()
      .AllowGrouping(true)   
      .AllowSelection(true)
      .AllowSorting(true)
      .AllowTextWrap(true)
      .FilterSettings(filter => { filter.FilterType(FilterType.Excel); })
      .SelectionType(SelectionType.Multiple)
      .ShowColumnChooser()
      .ShowSummary()
      .SummaryRow(row =>
          { row.ShowTotalSummary(true).Title("Sum").SummaryColumns(col =>
              {
                  col.SummaryType(SummaryType.Sum).Format("{0:C0}").DisplayColumn("EquityAmount").DataMember("EquityAmount").Add();
                  col.SummaryType(SummaryType.Sum).Format("{0:C0}").DisplayColumn("DesiredEquityAmount").DataMember("DesiredEquityAmount").Add();
                  col.SummaryType(SummaryType.Sum).Format("{0:C0}").DisplayColumn("MarketValueAmount").DataMember("MarketValueAmount").Add();
                  col.SummaryType(SummaryType.Sum).Format("{0:C0}").DisplayColumn("CashBalanceAmount").DataMember("CashBalanceAmount").Add();
              }).Add(); })
      .Columns(col =>
          {
              col.Field("AccountName").AllowEditing(false).Add();
              col.Field("EquityAmount").AllowEditing(false).TextAlign(TextAlign.Right).Format("{0:C0}").HeaderText("Equity").Add();
              col.Field("DesiredEquityAmount").TextAlign(TextAlign.Right).EditType(EditingType.Numeric).Format("{0:C0}").NumericEditOptions(new EditorProperties() { DecimalPlaces = 0 }).HeaderText("Desired Equity").Add();
              col.Field("MarketValueAmount").AllowEditing(false).TextAlign(TextAlign.Right).Format("{0:C0}").HeaderText("Market Value").Add();
              col.Field("CashBalanceAmount").AllowEditing(false).TextAlign(TextAlign.Right).Format("{0:C0}").HeaderText("Cash").Add();
              col.Field("Description").Add();
          })
      .GroupSettings(group => { group.GroupedColumns(col => { col.Add("AccountName"); }); })
      .ToolbarSettings(toolbar =>
          {
              toolbar.ShowToolbar().ToolbarItems(items =>
                  {
                      items.AddTool(ToolBarItems.Edit);
                      items.AddTool(ToolBarItems.Update);
                      items.AddTool(ToolBarItems.Cancel);
                  });
          }))

2) In the same grid above I have some javascript which will update the column values using: gridInstance.setCellValue(i, "DesiredEquityAmount", averageAmount); However, I have noticed that
a) the new data is not formatted as currency
b) the summary totals are not updated  - the totals aren't updated when I type in them manually either
c) the little red modification icon does not show up

How can I fix those issues?
3) In the same grid as above I would like to have the "Description" with type ahead - where it would have a list of suggested items. The user would not be restricted to the predefined items. How can this be implemented? (there would probably be less than 100 type ahead suggestions in the list)

4) I am dynamically filtering a grid by the following:             
var gridObj = $("#Grid").ejGrid("instance");
gridObj.filterColumn("AccountName", ej.FilterOperators.equal, filterValue, "and", true);
It looks like this is replacing the existing filter every time (and if so - do I really need the "and",true ??). Also, how would I go about adding / appending to the existing filter?

Regards, Jeff

1 Reply

RU Ragavee U S Syncfusion Team January 12, 2016 09:24 AM UTC

Hi Jeffrey,

Query #1: The summary total at the bottom of the grid shows incorrectly as "0" all the time

When having summaryRow enabled in Grid with dataSoure bound to grid using UrlAdaptor, we need to pass another parameter “aggregate” from the controller in addition to result and count.

We need to pass the array of data from the dataSource corresponding to the summaryColumn fields in the “aggregate” parameter. Please refer to the below code example.

public ActionResult DataSource(DataManager dm)

        {

            IEnumerable DataSource = OrderRepository.GetAllRecords();

            DataResult result = new DataResult();

            DataOperations operation = new DataOperations();

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

            if (dm.Aggregates != null)

            {

                foreach( var item in dm.Aggregates){

                    select.Add(item.Field);

                }

                var data = operation.PerformSelect(result.result, select);

                result.aggregate = data;

            }

               . . . .

               return Json(result, JsonRequestBehavior.AllowGet);
            }

public class DataResult

        {

            public IEnumerable result { get; set; }

            public int count { get; set; }

            public IEnumerable aggregate { get; set; }
        }


Query #2: When updating cell using setCellValue method, the red modification icon not appended and format not set to updated data

We considered this query “SetCellValue method improvements” as a usability feature and a support incident has been created under your account to track the status of this issue. Please log on to our support website to check for further updates.
https://www.syncfusion.com/account/login?ReturnUrl=/support/directtrac/incidents

Query #3: When updating cell in batchEdit mode, the summary totals are not updated  - the totals aren't updated when I type in them manually either

The summaryRow will be updated only after the edited value is saved to dataBase. But we can achieve you requirement using the CellSave event of the Grid. Please refer to the below code example.

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

              .Datasource(ds => ds.URL("/Home/DataSource").BatchURL("/Home/BatchUpdate").Adaptor(AdaptorType.UrlAdaptor))   

              . . . .

       .ClientSideEvents(eve=>eve.CellSave("cellSave"))

        )


<script type="text/javascript">

            function cellSave(args) {

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

                    var newvalue = args.value;// getting the new value

                    var oldvalue = args.rowData.Freight;// getting the old value

                    var extra = newvalue - oldvalue;//getting the difference in value

                    for (var i = 0; i < this.model.summaryRows.length; i++)

                        for (var j = 0; j < this.model.summaryRows[i].summaryColumns.length; j++) {

                            if (this.model.summaryRows[i].summaryColumns[j].dataMember == "Freight" && this.model.summaryRows[i].summaryColumns[j].summaryType == "sum"){

                                j = i;// finding the summaryRow to be modified

                                break;

                        }

                    }

                    var summary = ($(".e-gridSummaryRows:eq(" + j + ")").find("td.e-summaryrow")[args.cell.index()].innerHTML).replace(/[$,]/g, "")// getting the summaryValue of the corresponding summaryRow

                    var summaryval = (parseFloat(summary) + extra).toFixed(0);

                    summaryval = addCommas(summaryval);//add commas to the obtained value

                    $(".e-gridSummaryRows:eq(" + j + ")").find("td.e-summaryrow")[args.cell.index()].innerHTML = "$" + summaryval;//assigning the innerHTML of the summaryrow with updated value

                }

            }          


           </script>


Query #4: I would like to have the "Description" with type ahead - where it would have a list of suggested items.

We can achieve the above requirement using the “Editing Template” feature of the Grid. Please refer to the below online links

Online Documentation Link: http://help.syncfusion.com/js/grid/editing#cell-edit-template

Online Sample Link: http://mvc.syncfusion.com/demos/web/grid/edittemplate

Since you have expected a suggestion list to be displayed based on the the typed character, we suggest you to use the ejAutoComplete control in order to achieve your requirement. By enabling the showPopupButton property of the ejAutocomplete control, the editType acts similar to that of the dropdown control but with the predictive suggestion list as per your requirement.
Query #5: It looks like this is replacing the existing filter every time. how would I go about adding / appending to the existing filter?

We have analyzed the reported issue at our end with the code example that you have shared. We are sorry that the issue is not reproducible at our end. So could you please share the below details.

1.       Clear replication procedure
2.       Screenshot of the issue.
3.       Type of filter that you have enabled in your sample.
4.       If possible, please reproduce the issue in the below provided sample and share.

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

Sample Link: http://www.syncfusion.com/downloads/support/forum/121640/ze/Sample395122190

Regards,
Ragavee U S.

Loader.
Live Chat Icon For mobile
Up arrow icon