New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@lucasheight/kendo-grid-state

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lucasheight/kendo-grid-state

A helper library that implements a service to manage grid state during session or between sessions for Progress Kendo UI for Angular Grid.

  • 0.0.12
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
increased by200%
Maintainers
1
Weekly downloads
 
Created
Source

npm version

Angular kendo-grid-State

Purpose

A helper library that implements a service to manage grid state during session or between sessions for @Progress Kendo UI for Angular Grid.

How to use

Install

Install the Angular library with NPM:

    npm install --save @lucasheight/kendo-grid-state

Using the library

Configure the grid and column settings

An example project is included in source here. To view and edit on StackBlitz https://stackblitz.com/edit/angular-kendo-grid-state

  • Create an object that implements GridSettings.
  • Assign unique key for the state.
  • Assign the Storage type. E.g. sessionStorage or localStorage
  • Assign the initial grid state.
  • Assign the columns collection configuration.
export const appComponentGridSettings: GridSettings = {
  key: "exampleAppGridSettings",
  storage: sessionStorage,
  state: {
    skip: 0,
    take: 20,
    sort: [{ field: "ProductName", dir: "asc" }],
    filter: { logic: "and", filters: [] },
  },
  columns: [
    {
      title: "Id",
      field: "ProductID",
      editable: false,
      hidden: true,
      filterable: false,
    },
    //Or use a class object to construct a column
    new ColumnSettings({
      field: "ProductName",
      title: "Product Name",
      editable: true,
      filterable: true,
    }),
    //additional columns
  ],
};
Configure the component that hosts the grid
  • Add GridStateService to the providers.
  • Add the GRID_STATE constant to the providers and use the value of the GridSettings object created previously.
 @Component({
 providers: [
    GridStateService,
    { provide: GRID_STATE, useValue: appComponentGridSettings },
  ]
 })....

  • In the class constructor call the get() method on the GridStateService to populate the default settings. Note the public assessor on the gridStateService. This service requires to be public to be accessible in the html template if using the columnVisibilityChange event.
export class GridComponent {
  gridSettings: GridSettings;
  constructor(
    private service: AppService,
    public gridStateService: GridStateService
  ) {
    this.gridSettings = gridStateService.get();
  }
}
  • Every time an event is raised in your component that changes the grid state, call the set() method on the GridStateService. Example:
  public onStateChange = (e: DataStateChangeEvent): void => {
    this.loading = true;
    this.gridSettings.state = e;
    this.gridStateService.set(this.gridSettings);
    this.service.query(toODataString(this.gridSettings.state));
  };
Configure the html template

Add a <kendo-grid></kendo-grid> to the template. Use an *ngFor to iterate over the configured columns array. If your grid makes use of column templates, use an *ngIf on the template to filter for the required field. Example below.

Configure the grid attributes for the managed states. Config the columnVisibilityChange event if required. The handler for this event is available on the GridStateService. (columnVisibilityChange)="gridStateService.onVisibilityChange($event)"

Full template example

<h1>Northwind Products</h1>

<kendo-grid
  #grid
  [data]="data$ |async"
  [pageSize]="gridSettings.state.take"
  [pageable]="{
  buttonCount:5,
  info:true,
  type:'numeric',
  pageSizes:true,
  previousNex:true
  }"
  [loading]="loading"
  [filter]="gridSettings.state.filter"
  [groupable]="false"
  [group]="gridSettings.state.group"
  [sortable]="true"
  [skip]="gridSettings.state.skip"
  [sort]="gridSettings.state.sort"
  [filterable]="true"
  [columnMenu]="true"
  (dataStateChange)="onStateChange($event)"
  (columnVisibilityChange)="gridStateService.onVisibilityChange($event)"
>
  <kendo-grid-column
    *ngFor="let col of gridSettings.columns"
    [title]="col.title"
    [field]="col.field"
    [hidden]="col.hidden===undefined?false:col.hidden"
    [filterable]="col.filterable"
    [editable]="col.editable===undefined?true:col.editable"
  >
    <ng-template
      *ngIf="col.field==='ProductId'"
      kendoGridCellTemplate
      let-dataItem
    >
    {{dataItem.ProductId}} - {{dataItem.ProductName}}
    </ng-template>
  </kendo-grid-column>
</kendo-grid>

Demo

https://angular-kendo-grid-state.stackblitz.io

Keywords

FAQs

Package last updated on 25 May 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc