Save/Load the Grid's state.
A live JavaScript/jQuery example of jqxGrid, the jQWidgets Grid component, with its complete source code below. It is one of 139 jqxGrid demos for jQuery.
showfilterrow property – Shows or hides the filter row.selectionmode property – Sets or gets the selection mode.theme property – Sets the widget's theme.autoheight property – Sets or gets the height of the grid to be equal to the summary height of the grid rows.width property – Sets or gets the Grid's width.autosavestate property – Determines whether the Grid automatically saves its current state.autoloadstate property – Determines whether the Grid automatically loads its current state(if there's already saved one).columns property – Sets the Grid columns.columnsresize property – Enables or disables the columns resizing.columnsreorder property – Enables or disables the columns reordering.filterable property – Enables or disables the Grid Filtering feature.pageable property – Enables or disables the Grid Paging feature.sortable property – The sortable property enables or disables the sorting feature.source property – Sets and gets the source.loadstate method – Loads the Grid's state.savestate method – Saves the Grid's current state.To run it in your own page, load jqx.base.css, a theme and the library files below from npm (npm install jqwidgets-scripts) or the jsDelivr CDN, then add the markup and the script. jQuery is not required: jqxcore.js provides $. Getting started with jqxGrid shows the setup step by step.
The page loads jqx.base.css, a theme and these library files: jqxcore.js, jqxdata.js, jqxbuttons.js, jqxscrollbar.js, jqxlistbox.js, jqxdropdownlist.js, jqxmenu.js, jqxgrid.js, jqxgrid.pager.js, jqxgrid.sort.js, jqxgrid.filter.js, jqxgrid.storage.js, jqxgrid.columnsresize.js, jqxgrid.columnsreorder.js, jqxgrid.selection.js, jqxpanel.js, jqxcheckbox.js.
It also loads helper scripts of this demo site, which are not part of the library: demos.js (getWidth() and other layout helpers).
$(document).ready(function () {
var url = "../sampledata/orders.xml";
// prepare the data
var source =
{
datatype: "xml",
datafields: [
{ name: 'ShipName', map: 'm\\:properties>d\\:ShipName' },
{ name: 'ShipCity', map: 'm\\:properties>d\\:ShipCity' },
{ name: 'ShipCountry', map: 'm\\:properties>d\\:ShipCountry' }
],
root: "entry",
record: "content",
id: 'm\\:properties>d\\:OrderID',
url: url,
pager: function (pagenum, pagesize, oldpagenum) {
// callback called when a page or page size is changed.
}
};
var dataAdapter = new $.jqx.dataAdapter(source);
$("#grid").jqxGrid(
{
width: getWidth('Grid'),
source: source,
selectionmode: 'multiplerowsextended',
sortable: true,
pageable: true,
autoheight: true,
autoloadstate: false,
autosavestate: false,
columnsresize: true,
columnsreorder: true,
showfilterrow: true,
filterable: true,
columns: [
{ text: 'Ship Name', filtercondition: 'starts_with', datafield: 'ShipName', width: 250 },
{ text: 'Ship City', datafield: 'ShipCity', width: 200 },
{ text: 'Ship Country', datafield: 'ShipCountry' }
]
});
$("#saveState").jqxButton({ theme: theme });
$("#loadState").jqxButton({ theme: theme });
var state = null;
$("#saveState").click(function () {
// save the current state of jqxGrid.
state = $("#grid").jqxGrid('savestate');
})
;
$("#loadState").click(function () {
// load the Grid's state.
if (state) {
$("#grid").jqxGrid('loadstate', state);
}
else {
$("#grid").jqxGrid('loadstate');
}
});
});
<div id="grid">
</div>
<div style="margin-top: 30px;">
<input type="button" id="saveState" value="Save State">
<input type="button" id="loadState" value="Load State">
</div>