Comments (3)
Hi Ninopetrovic,
You can get the current Grid state by using the grid.getPersisteData() method which will return the state as JSON string. You need to save the grid state when you log out and you can reuse the state in the created event of Grid component. Please refer to the below code example, documentation link and sample link.
`@Component({
selector: 'control-content',
template: <button (click)='getData()'>Logout
<ejs-grid #grid id="Grid" (created)="created($event)" [dataSource]='data' allowFiltering=true [allowPaging]='true'
allowResizing=true allowReordering=true>
. . .
'
})
export class DefaultComponent implements OnInit {
. . .
created(e){
if(this.state !=undefined){
var gridState = JSON.parse(this.state);
// set the Grid state while rendering
this.grid.setProperties(gridState,false);
}
}
getData(e){
this.state = this.grid.getPersistData();
console.log(this.state);
}
}
`
Documentation: https://ej2.syncfusion.com/angular/documentation/api/grid#created
Sample : https://stackblitz.com/edit/angular-kvww9x-igcvwj?file=default.component.ts
Regards,
Thavasianand S.
from ej2-javascript-ui-controls.
hello,
I did this and works ok. But now i am trying to implement a dropdown menu where you can select which view (state of grid saved in DB) do you want to work on. I am saving persistData as string in my DB and then loading it in on option click with setProperties but i am getting this error:
from ej2-javascript-ui-controls.
Hi Ninopetrovic,
We have validated your query and created sample based on your requirement. Here, we have get the grid state and set the state to grid dynamically. Here, we have get grid state by using button(getData) click then save the grid state to window(window.localStorage)local storage. After that, we have refreshed the page then, we have set the grid state(previously saved data in localStorage) by using button(setData) click. Please find the below code example and sample for your reference.
@Component({ selector: 'control-content', template:
<button (click)='getData()'>getData
<button (click)='setData()'>setData
<ejs-grid #grid id="Grid" [dataSource]='data' allowFiltering=true [allowSorting]='true' [allowPaging]='true'
allowResizing=true allowReordering=true>
...
})
export class DefaultComponent implements OnInit {
public data: Object[];
public state: any;
public newGrid: any;
public display: any = false;
public flag: any = false;
@ViewChild('grid')
public grid: GridComponent;
ngOnInit(): void {
this.data = orderDetails;
}
getData(e) {
this.state = this.grid.getPersistData();
console.log(JSON.parse(this.state));
window.localStorage.setItem("st1", this.state);
}
setData(e) {
this.grid.setProperties(JSON.parse(window.localStorage.getItem("st1")));
}
}`
After running the sample, perform any operation(sorting, filtering, etc) then get grid state by clicking getData button. After that refresh the page, then set the grid state to grid by using setData button.
Sample link: https://stackblitz.com/edit/angular-kvww9x-gkz7ah?file=default.html
Could you please share the below details, it will be helpful to provide a better solution as early as possible.
• Share details regarding how can you set grid state dynamically.
• Share sample or full grid code example if it is possible.
Regards,
Rahul Narayanasamy.
from ej2-javascript-ui-controls.
Related Issues (20)
- PdfViewer: When creating a signature field the background color is ignored. HOT 2
- Data Grid column template not rendering in React HOT 4
- Security issue HOT 4
- visual picker HOT 2
- web component support HOT 2
- CSS styles are not exported from the syncfusion packages HOT 4
- CSS explicitly needs to be set as having side effects in order to work with Parcel. HOT 4
- My scheduler component crashes since resourceCollection can be empty HOT 2
- spreadsheet to keep zero digit HOT 2
- Why is the version of `@types/node` set at a static 18.11.11? I get an "arrow key" prompt. HOT 1
- Error alert when opening excel file HOT 3
- npm run error HOT 3
- Firefox: no execCommand HOT 2
- Content Security Policy requires 'unsafe-eval' for script-src HOT 2
- this.lastPos scope is window and not TreeInterSectionObserver HOT 3
- unset-value 1.0 has a high security vulnerability, fixed in 2.0.1 HOT 3
- The esm files inside `dist/es6` folder should end with `.mjs` HOT 5
- Integration with Azure Data lake Storage V2 HOT 1
- npm install @syncfusion/[email protected] fails (missing dep) HOT 1
- Supported data sources for update-spline real-time streaming chart HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ej2-javascript-ui-controls.