State Persistence
21 Feb 20221 minute to read
Essential JS 2 has support for persisting component’s state across page refreshes or navigation. To enable this feature, set EnablePersistence
property as true to the required component. This will store the component’s state in browser’s localStorage
object on page unload
event. For example, we have enabled persistence to grid component in the following code.
@Html.EJS().Grid("check").DataSource(dataManger =>
{
dataManger.Url("http://services.odata.org/V4/Northwind/Northwind.svc/Products").CrossDomain(true).Adaptor("ODataV4Adaptor");
}).Columns(col =>
{
col.Field("ProductID").HeaderText("Product ID").Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
col.Field("ProductName").HeaderText("Product Name").Width("150").Add();
col.Field("UnitPrice").HeaderText("Supplier ID").Width("130").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
col.Field("UnitsInStock").HeaderText("QuantityPerUnit").Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add();
col.Field("Discontinued").HeaderText("Discontinued").Width("140").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Center).Type("boolean").DisplayAsCheckBox(true).Add();
})
.EnablePersistence()
.AllowPaging()
.PageSettings(page=>page.PageCount(5))
.Render()