)
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: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Essential JS2

Syncfusion jQuery based widgets are no longer in active development. Switch to our pure JavaScript based next generation Essential JS 2 library.

Syncfusion Feedback

How to collapse all the group caption rows in initial rendering of Grid?

Platform: jQuery |
Control: ejGrid |
Published Date: January 16, 2018 |
Last Revised Date: February 25, 2020
Tags: grouping

This explains that collapsing all Group Caption Rows at initial Rendering of ejGrid.

Solution:

We can collapse all the Group Caption Rows at initial rendering using dataBound event and collapseAll method of ejGrid. The dataBound event will be triggered when the grid is bound with data at initial rendering. In this event we have to use collapseAll method to collapse all the group caption rows.

To collapse all the Group Caption Rows during paging we have to use actionComplete event and collapseAll method of ejGrid. The actionComplete event will be triggered for every grid action success event. In this event we need to check the requestType as paging and call the collapseAll method.

The following code example demonstrates how to collapse all Group Caption rows at initial rendering and paging:

JS:

1. Render the Grid Control.

<div id="Grid"></div>
 
    <script type="text/javascript">
        $("#Grid").ejGrid({
            // the datasource "window.gridData" is referred from jsondata.min.js
            dataSource: window.gridData,
            allowPaging: true,
            allowGrouping: true,
            actionComplete: "Complete",
            groupSettings: { groupedColumns: ["CustomerID"] },
            dataBound: "dataBound",
            columns: [
                    { field: "OrderID", headerText: "Order ID" },
                    { field: "EmployeeID", headerText: "Employee ID" },
                    { field: "CustomerID", headerText: "Customer ID" },
            ]
        });
    </script>
 

 

MVC:

@(Html.EJ().Grid<object>("Grouping")
        .Datasource((IEnumerable<object>)ViewBag.datasource)
        .AllowGrouping()
        .AllowSorting()
        .AllowPaging()
        .GroupSettings(group => { group.GroupedColumns(col => { col.Add("CustomerID"); }); })
        .Columns(col =>
        {
            col.Field("OrderID").HeaderText("Order ID").Add();
            col.Field("EmployeeID").HeaderText("Employee ID").Add();
            col.Field("CustomerID").HeaderText("Customer ID").Add();
        })
        .ClientSideEvents(eve => eve.ActionComplete("Complete").DataBound("dataBound"))
)

 

ASP.NET:

<ej:Grid ID="OrdersGrid" runat="server" AllowGrouping="True" AllowPaging="True">
   <GroupSettings GroupedColumns="CustomerID"></GroupSettings>
     <ClientSideEvents ActionComplete="Complete" DataBound="dataBound" />
      <Columns>
           <ej:Column Field="OrderID" HeaderText="Order ID" />
           <ej:Column Field="EmployeeID" HeaderText="Employee ID" />
           <ej:Column Field="CustomerID" HeaderText="Customer ID" />
      </Columns>
</ej:Grid>            

 

ASP.NET CORE:

<ej-grid id="FlatGrid" allow-paging="true" allow-grouping="true" action-complete="Complete" databound="dataBound" datasource="ViewBag.dataSource">
    <e-group-settings grouped-columns=new List<string>() {"CustomerID"}></e-group-settings>
    <e-columns>
        <e-column field="OrderID" header-text="Order ID"></e-column>
        <e-column field="EmployeeID" header-text="Employee ID"></e-column>
        <e-column field="CustomerID" header-text="Customer ID"></e-column>
    </e-columns>
</ej-grid>

 

Angular:

<ej-grid #grid id="Grid" [dataSource]="gridData" [allowPaging]="true" [allowGrouping]="true" [groupSettings]="groupsettings" (actionComplete)="Complete($event)">
    <e-columns>
        <e-column field="OrderID" headertext="Order ID"></e-column>
        <e-column field="EmployeeID" headertext="Employee ID"></e-column>
        <e-column field="CustomerID" headertext="Customer ID"></e-column>
    </e-columns>
</ej-grid>

 

TS File:

For angular platform use ngAfterViewInit event instead of dataBound event

@ViewChild('grid') GridModel: EJComponents<any, any>;
 
    export class GridDetailTempComponent {
 
      public gridData: any;
    
      groupsettings: any;
   
      constructor() {
        
        //The datasource "window.gridData" is referred from 'http://js.syncfusion.com/demos/web/scripts/jsondata.min.js
        this.gridData = (window as any).gridData;
        
        this.groupsettings = { groupedColumns: ["CustomerID"] } ;
 
    }
    Complete(e:any){
        if(e.requestType == "paging") {
            this.GridModel.widget.collapseAll();
        }
    }
    ngAfterViewInit(){
       var grid = this.GridModel.widget;
       grid.collapseAll();
    }
 
}

 

JS:

2. In actionComplete and dataBound event we used the collapseAll method of ejGrid to collapse all Grid Rows.

function Complete(args) {
    if (args.requestType == "paging") {
       this.collapseAll();
    }
 }
 
function dataBound(args) {
    this.collapseAll();
}
 

 

Result:

 

Collapsed Grid

ADD COMMENT
You must log in to leave a comment
Comments
Elisabeth
Apr 27, 2020

this.collapseAll() is undefined

Reply
Padmavathy Kamalanathan [Syncfusion]
Apr 29, 2020

Hi Elisabeth,

Thanks for contacting Syncfusion Support.

QUERY: this.collapseAll() is undefined

We are unable to reproduce the reported issue at our end. Collapsing the group caption rows in initial rendering of grid works fine. We have also prepared and shared you sample for your reference.

Please check the below sample,

Sample

Please share us the below details so that we could proceed further,

  1. Complete grid rendering code
  2. Please confirm whether you are using Essential Studio Version 18.1.0.42 or share us your version details
  3. Share us the screenshot of error with stack trace (if any)
  4. Video showing the issue

Regards,

Padmavathy Kamalanathan

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

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

Live Chat Icon For mobile
Live Chat Icon