How to persist state of collapse/expand ejGrid Grouping
Hello,
Attachment: Capture_bdcb9492.zip
I would like to know if it's possible to persist the state of items (grouping) collapse or expand ?
thanks
Attachment: Capture_bdcb9492.zip
SIGN IN To post a reply.
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.
JsPlayground: https://jsplayground.syncfusion.com/ipfav2t2
Refer the help documentation.
Regards,
Thavasianand S.
UN
Unknown
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.
KB link: https://www.syncfusion.com/kb/6312/how-to-store-retrieve-grid-model-values-into-from-database
Regards,
Thavasianand S.
UN
Unknown
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.
UN
Unknown
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.
JsPlayground link: https://jsplayground.syncfusion.com/m4ucg5sd
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.
UN
Unknown
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
SIGN IN To post a reply.
- 9 Replies
- 3 Participants
-
UN Unknown
- Oct 9, 2018 08:01 AM UTC
- Oct 12, 2018 10:26 AM UTC