-2

Page onload slickgrid is loaded and Pagination is working but on cell click slick grid dataset value updated (new data added) but pagination value not update(didn't updatePagination). How to again apply pagination on click event. backendServiceApi not update the updated item count. How to call backendServiceApi again with the updated data. I'm using Pagination with Backend server odata method.

1 Answers1

0

Your question is really missing details, but if you want to change page (pagination) after an on cell click. You can now do it through the new PaginationService that I added recently to the lib. In code that would be

<angular-slickgrid 
    gridId="grid5" 
    [columnDefinitions]="columnDefinitions" 
    [gridOptions]="gridOptions"
    [dataset]="dataset" 
    (onGridStateChanged)="gridStateChanged($event)"
    (onAngularGridCreated)="angularGridReady($event)">
</angular-slickgrid>

then in your Component

export class MyExample implements OnInit {
  angularGrid: AngularGridInstance;
  columnDefinitions: Column[];
  gridOptions: GridOption;
  dataset = [];

  angularGridReady(angularGrid: AngularGridInstance) {
    this.angularGrid = angularGrid;
  }

  defineGrid() {
    this.columnDefinitions = [
      {
        id: 'action', name: 'Action', field: 'action',  
        onCellClick: (e, args) => {
          // maybe do something with args or args.dataContext?
          this.goToPageNumber(2);
        },
      },
    ];
  }

  goToPageNumber(page: number) {
    this.angularGrid.paginationService.goToPageNumber(page);
  }

  goToFirstPage() {
    this.angularGrid.paginationService.goToFirstPage();
  }

  goToLastPage() {
    this.angularGrid.paginationService.goToLastPage();
  }
}

If you wish to do it on any column or cell clicked, you can use (sgOnClick)="onCellClicked($event.detail.eventData, $event.detail.args)" in your View and then in your Component onCellClicked(e, args) { ... }

But that might not be what you're asking for, again your questions is missing substance. Please give more details to your question and add code. What is your problem anyway? Also note Pagination only works with a BackendServiceApi which are OData or GraphQL (or even a custom one).

Oh and I'm the author of Angular-Slickgrid if you haven't noticed.

ghiscoding
  • 12,308
  • 6
  • 69
  • 112
  • Page onload slickgrid is loaded and Pagination is working but on cell click slick grid dataset value updated (new data added) but pagination value not update(didn't updatePagination). How to again apply pagination on click event. backendServiceApi not update the updated item count. How to call backendServiceApi again with the updated data. I'm using Pagination with Backend server odata method. – RashmiPatil Nov 14 '19 at 12:45
  • If you add item to the grid via the Grid Service, it will recalculate the Pagination by itself since internally it subscribes to an `onItemAdded` event [here](https://github.com/ghiscoding/Angular-Slickgrid/blob/master/src/app/modules/angular-slickgrid/services/pagination.service.ts#L84) but if you do it outside of that service, it won't trigger a Pagination refresh, so I recommend you to add an item via the Grid Service, you can read the [Wiki](https://github.com/ghiscoding/Angular-Slickgrid/wiki/Add,-Update-or-Highlight-a-Datagrid-Item). Other ways to do it are much more complicated – ghiscoding Nov 14 '19 at 15:51
  • Thank You for your quick response. It helps me. But updateItem() will not update the entire dataset data and addItem() will append the dataset not change the entire dataset data. So explain me how to update entire dataset so that it will recalculate pagination by itself internally. – RashmiPatil Nov 15 '19 at 07:08
  • If your `totalItems` is updated externally through the Grid Options `pagination.totalItems`, then you can call `this.angularGrid.refreshPagination(true)` that will internally call the `recalculateFromToIndexes` method. That is the last comment I will write, if that doesn't work then you're out of luck. – ghiscoding Nov 16 '19 at 22:43