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

How to persist state of collapse/expand ejGrid Grouping

Hello, 

I would like to know if it's possible to persist the state of items (grouping) collapse or expand ?


thanks

Attachment: Capture_bdcb9492.zip

9 Replies

TS Thavasianand Sankaranarayanan Syncfusion Team October 9, 2018 10:57 AM UTC

Hi Foulont,  

Thanks for contacting Syncfusion support. 

As per your given detail we suspect that you want to persist the grouped columns in Grid. So, we suggest you to enable enbalePersistence property of ejGrid control. 

Refer the below code example. 


$(function () { 
            $("#Grid").ejGrid({ 

                 ---- 

                allowGrouping: true, 
               enablePersistence:true, 
                groupSettings: { groupedColumns: ["ShipCity"] }, 
                toolbarSettings: { showToolbar: true, customToolbarItems: ["Expand", "Collapse", { templateID: "#Refresh" }] }, 
                toolbarClick: "onToolBarClick", 
                columns: [ 

                             ----- 

               
            }); 
        }); 


We have prepared a simple JsPlayground sample in the following link. 


Refer the help documentation. 



Regards, 
Thavasianand S. 



FG Foulont Gaetan October 9, 2018 11:26 AM UTC

Yes I know this properties.

But I want to save the state of the grouping inside the grid. It is possible ?

Suppose we collapse Ship City: Albuquerque, and Ship City: Albuquerque. When I reload the page I want see Ship City: Albuquerque, and Ship City collapse not expand.

Thanks in advance 



TS Thavasianand Sankaranarayanan Syncfusion Team October 9, 2018 11:48 AM UTC

Hi Foulont, 

We have already discuss about above reported query in the following knowledge base documentation. 


Regards, 
Thavasianand S. 



FG Foulont Gaetan October 9, 2018 12:35 PM UTC

I don't want to persist on database just on localstorage.

I have set enablePersistence to true on my grid setting, it's working like a charm.

But the expanded or collapsed row are not  persist. 


I just want to persist what you see in yellow highlighted (collapsed) :



VN Vignesh Natarajan Syncfusion Team October 10, 2018 11:23 AM UTC

Hi Foulont, 

 
Sorry for the inconvenience caused. 
 

From your shared details we are able to understand that you need to persist some the grouped value to be in collapsed state after reloading. But currently we do not have support to achieve your requirement.   
 
 
Regards, 
Vignesh Natarajan. 



FG Foulont Gaetan October 10, 2018 01:24 PM UTC

Hello,

Well ok, could you explain me any workaround to do this ?

thx


TS Thavasianand Sankaranarayanan Syncfusion Team October 11, 2018 10:32 AM UTC

Hi Foulont, 

We can achieve your requirement using the window.localStorage and dataBound event, expandCollapse method of ejGrid control. Initially we save the state of the Grid into window.localStorage in an external button click event and when we refresh the page we set the expand/collapse state to the Grid in the dataBound event.  

Refer the below code example. 


<div class="content-container-fluid"> 
        <div class="row"> 
              <input type="button" onclick="SaveState()" value="SaveTheState" /> 
            <div class="cols-sample-area"> 
                <div id="expandCollapse"></div> 
            </div> 
        </div> 
    </div> 
 
    <script type="text/javascript"> 
        $(function () { 
            $("#expandCollapse").ejGrid({ 
                // the datasource "window.gridData" is referred from jsondata.min.js 
                dataSource: window.gridData, 
                 
                 ---- 
 
                columns: [ 
 
                          ---- 
 
                ], 
                 
               // Set the expand/collapse into grid when we refresh the page 
               dataBound: function(args){ 
                  var value = window.localStorage.getItem("ejGridCollapseExpand"); // Get the data of expand/collapse from window.localStorage 
                  var val = ej.parseJSON(value); 
                  for(var j=0; j<val.length; j++){ 
                     var row = this.getContentTable().find('tr.e-groupcaptionrow')[val[j]]; 
                     this.expandCollapse($(row).find("td.e-recordplusexpand > div").first());// expand/collapse the data using expandCollapse method of ejGrid 
                  } 
                } 
              }); 
             }); 
  
              // save the current state of the Grid for expand /collapse 
              function SaveState(args){ 
                var collapsedGroup = $(".e-grid .e-recordpluscollapse"); 
                var model = []; 
                for(var i = 0; i<collapsedGroup.length; i++){ 
                  var groupedRow = $(collapsedGroup[i]).parent('.e-groupcaptionrow').index(); 
                  if(groupedRow != 0 && !ej.isNullOrUndefined(groupedRow)) 
                     groupedRow = groupedRow / 2; 
                     model.push(groupedRow); 
                  } 
                window.localStorage.setItem("ejGridCollapseExpand", JSON.stringify(model));  //set that expand/collapse data into the window.localStorage 
              } 
         
    </script> 


Note: Please change the Grid ID and window.localStorage setItem/getItem name every time you ran the sample. Because model get persisted for every page refresh. 

We have prepared a simple JsPlayground sample in the following link. 


We have discuss about how to get or set the values into window.localStorage in the following knowledge base documentation. 


Refer the help documentation. 



Regards, 
Thavasianand S. 



FG Foulont Gaetan October 12, 2018 09:04 AM UTC

Hello,

Thanks it works !!




VN Vignesh Natarajan Syncfusion Team October 12, 2018 10:26 AM UTC

Hi Foulont, 


Thanks for the update.  


We are happy to hear that your query has been resolved by our solution.  


Please get back to us of you have further queries 


Regards, 
Vignesh Natarajan 


Loader.
Live Chat Icon For mobile
Up arrow icon