-
Notifications
You must be signed in to change notification settings - Fork 162
Grid State Persistence
Version | User | Date | Notes |
---|---|---|---|
0.1 | Hristo Anastasov | 06.11.2019 | Specification for State Persistence directive and API |
0.2 | Hristo Anastasov | 06.11.2019 | Specification for State Persistence directive and API |
0.3 | Hristo Anastasov | 06.11.2019 | Final version of API exposed. |
0.4 | Hristo Anastasov | 19.11.2019 | Refining return type and parameters of public methods. |
- Radoslav Mirchev | Date:
- Konstantin Dinev | Date:
The Grid State Persistence feature aims at providing an easy out-of-the-box way for developers to save/and restore the state of the
IgxGrid
, (IgxTreeGrid
andIgxHierarchicalGrid
yet to be implemented). Once theIgxGridState
directive is applied, the developer will be able to get the current state of a feature or all features usinggetState
method, and later apply it on the grid usingsetState
method (see API).
Developer:
- Story 1. As a citizen developer, I want to get the grid state on API call.
- Story 2. As a citizen developer, I want to pass an options object describing what features state are not needed to be saved.
- Story 2. As a citizen developer, I want to get only the columns state or certain feature state on API call.
- Story 3. As a citizen developer, I want to restore the state by passing in the state object retrieved by the
getState
method as an argument to thesetState
method.
End user:
- Story 1: As an end user, I want to see the same grid state as I left it on my last visit of the page.
- After applying the
IgxGridState
directive on the grid, callinggetState
method on the directive will return a serialized object implementing theIGridState
, (ITreeGridState
,IHierarchicalGridState
yet to be aded) interface, containing:
- sorting expressions
- groupby expressions
- filtering expressions
- columns state (pinned, sortable, filterable, movable, hidden, summary, hasSummary, width, header) implementing the
IColumnState
interface:
interface IColumnState {
field: string;
header?: string;
width?: string;
dataType?: string;
pinned?: boolean;
sortable?: boolean;
filterable?: boolean;
movable?: true;
hidden?: boolean;
}
- selection state
- paging state
- After applying the
IgxGridState
directive, callinggetState
with afalse
argument will return a non-serialized object implementing theIGridState
, (ITreeGridState
,IHierarchicalGridState
yet to be added) interface.
3.1. End User Experience The user experience is the same as user has applied sorting, filtering, etc, through the UI.
3.2. Developer Experience
The developer is applying the IgxGridState
directive on the grid, which allows working with the State Persistence API to easily retrieve/set the grid state.
Based on the use case, the developer may choose to apply the IgxGridState
directive along with an optional options
object implementing the IGridStateOptions
interface:
interface IGridStateOptions {
selection?: boolean;
filtering?: boolean;
advancedFiltering?: boolean;
paging?: boolean;
sorting?: boolean;
groupby? : boolean;
columns?: boolean;
}
<igx-grid #grid [igxGridState]="options" [data]="localData" ></igx-grid>
@ViewChild(IgxGridStateDirective, { static: true }) public state;
public options = {
selection: false,
filtering: true,
advancedFiltering: false,
paging: true,
sorting: true,
groupby: false,
columns: true
};
public ngOnInit() {
this.router.events.pipe(take(1)).subscribe((event: NavigationStart) => {
this.saveGridState();
});
this.restoreGridState();
}
public saveGridState() {
const state = this.state.getState();
// save `state` object to any database, localStorage, etc.
}
public restoreGridState() {
// retrieve `state` from the data storage
this.state.setState(state);
}
Every key/value pair in the IGridStateOptions
indicates if a certain feature state will be saved/restored.
3.3. Globalization/Localization
N/A
3.4. User Interface
N/A
Name | Description | Type | Default value | Valid values |
---|---|---|---|---|
options |
Object containing the features which state to be saved/restored | object |
IGridStateOptions |
private _options: IGridStateOptions = {
columns: true,
filtering: true,
advancedFiltering: true,
sorting: true,
groupby: true,
paging: true,
selection: true
};
Name | Description | Return type | Parameters |
---|---|---|---|
getState(params) |
Returns the current grid state in a serialized object, when called without arguments. Can be called with parameters to return the state only for a particular feature. Calling with a false serialize argument will return a non-serialized object. |
IGridState , string
|
feature: string , string[] , serialize: boolean
|
setState(gridState) |
Restores the grid state or a certain feature state from a state object, either serialized or non-serialized. | void | object: IGridState
|
N/A
N/A
Assumptions | Limitation Notes |
---|---|
Filtering depends on knowing the column data types. If Filtering is enabled, columns are enabled too. |
N/A