App.component.html
<button ejs-button (click)="save($event)">save</button> // save the persisted data
<button ejs-button (click)="load($event)">load</button> // load the persisted data in the grid
<ejs-grid #grid [dataSource]='data' [allowSorting]='true' [allowGrouping]='true' [allowPaging]=true
(dataBound)="dataBound($event)" height='210px' [toolbar]='toolbarOptions'>
<e-columns>
<e-column field='OrderID' headerText='Order ID' textAlign='right' width=120></e-column>
<e-column field='CustomerID' headerText='Customer ID' width=150></e-column>
<e-column field='Freight' width=150></e-column>
<e-column field='ShipName' headerText='Ship Name' width=150></e-column>
</e-columns>
</ejs-grid>
App.component.ts
export class AppComponent implements OnInit {
@ViewChild('grid', { static: true }) public grid: GridComponent;
public data: object[];
public editSettings: EditSettingsModel;
public toolbarOptions: ToolbarItems[];
public resetProperties: object;
public count = 0;
ngOnInit(): void {
this.data = hierarchyOrderdata;
this.toolbarOptions = ['Search'];
}
dataBound(args) {
}
save(args) {
// get the persisted data of the grid
var savedProperties = JSON.parse(
this.grid.getPersistData()
);
console.log(savedProperties);
// if you don’t need some persisted settings (like filtering, searching, grouping etc.,) then set the default value to those setting.
//default value of pagesettings
savedProperties.pageSettings = { currentPage: 1, pageCount: 8, pageSize: 12 };
//default value of sortSettings
savedProperties.sortSettings = { columns: [] };
//default value of filterSettings
savedProperties.filterSettings = {};
//default value of groupSettings
savedProperties.groupSettings = { columns: [], showDropArea: true, showToggleButton: false, disablePageWiseAggregates: false,
allowReordering: false, showUngroupButton: true, showGroupedColumn: false };
//default value of searchSettings
savedProperties.searchSettings = { key: "", fields: [], operator: "contains", ignoreCase: true, ignoreAccent: false };
//default value of Selection settings
savedProperties.selectedRowIndex = -1
console.log(savedProperties);
this.resetProperties = savedProperties;
}
load(args) {
if (this.resetProperties) {
// set the modified persisted properties to the grid
this.grid.setProperties(this.resetProperties);
}
}
}
|