Having trouble getting help?
Contact Support
Contact Support
State persistence in Angular Query builder component
26 Apr 20244 minutes to read
State persistence allows you to maintain the current state in the browser’s localStorage
even if the browser is refreshed or if you move to the next page within the browser. State persistence stores the Query Builder’s rule
object in the local storage when the enablePersistence
is defined to true.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { QueryBuilderModule } from '@syncfusion/ej2-angular-querybuilder'
import { enableRipple } from '@syncfusion/ej2-base'
import { Component, OnInit } from '@angular/core';
import { RuleModel } from '@syncfusion/ej2-angular-querybuilder';
import { hardwareData } from './datasource';
@Component({
imports: [
QueryBuilderModule
],
standalone: true,
selector: 'app-root',
template: `<!-- To render Query Builder. -->
<ejs-querybuilder #querybuilder width="70%" [dataSource]="data" [rule]="importRules" enablePersistence="true" >
<e-columns>
<e-column field="TaskID" label="Task ID" type="number"></e-column>
<e-column field="Name" label="Name" type="string"></e-column>
<e-column field="Category" label="Category" type="string"></e-column>
<e-column field="SerialNo" label="SerialNo" type="string"></e-column>
<e-column field="InvoiceNo" label="InvoiceNo" type="string"></e-column>
<e-column field="Status" label="Status" type="string"></e-column>
</e-columns>
</ejs-querybuilder>`
})
export class AppComponent implements OnInit {
public data?: Object[];
public importRules?: RuleModel;
ngOnInit(): void {
this.data = hardwareData;
this.importRules = {
'condition': 'or',
'rules': [{
'label': 'Category',
'field': 'Category',
'type': 'string',
'operator': 'equal',
'value': 'Laptop'
},
{
'condition': 'and',
'rules': [{
'label': 'Status',
'field': 'Status',
'type': 'string',
'operator': 'notequal',
'value': 'Pending'
},
{
'label': 'Task ID',
'field': 'TaskID',
'type': 'number',
'operator': 'equal',
'value': 5675
}]
}]
};
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));