Ag grid Server side pagination

前端 未结 2 1612
走了就别回头了
走了就别回头了 2021-02-04 10:59

I\'m trying to implement a server side pagination in ag-Grid where I\'ll make a SOAP call each time I click on the next/previous button. I have already implemented the function

相关标签:
2条回答
  • 2021-02-04 11:42

    After digging ag-grid Library for the whole day , I finally found the solution.

    First Lets include the following options in our GridOptions;

    GridOptions :

      gridOptions: GridOptions = {
        pagination: true,
        rowModelType: 'infinite',
        cacheBlockSize: 20, // you can have your custom page size
        paginationPageSize: 20 //pagesize
      };
    

    GridReady CallBack

    After the Grid is ready, Set a datasource e.g

    onGridReady(params: any) {
        this.gridApi = params.api;
        this.gridApi.setDatasource(this.dataSource) // replace dataSource with your datasource
      } 
    

    Data Source Object : dataSource object is called by ag-grid when you go to next page and thus fetches data.

    getRows functions provides you with start and end index of the particular page.

    params.successCallback : It takes two arguments, first the data related to page and second is totalRecords. Ag-grid uses the second parameter to decide total pages.

    dataSource: IDatasource = {
        getRows: (params: IGetRowsParams) => {
    
          // Use startRow and endRow for sending pagination to Backend
          // params.startRow : Start Page
          // params.endRow : End Page
    
          //replace this.apiService with your Backend Call that returns an Observable
          this.apiService().subscribe(response => {
    
            params.successCallback(
              response.data, response.totalRecords
            );
    
          })
        }
      }
    

    Example Api Service : This is an example api service that i have used

    apiService() {
        return this.httpclient.get('https://raw.githubusercontent.com/ag-grid/ag-grid/master/packages/ag-grid-docs/src/olympicWinners.json')
      }
    

    I have uploaded this example on GitHub.

    0 讨论(0)
  • 2021-02-04 11:43

    ag-grid (version 10 onwards) doesn't support server side pagination. If you want to implement server side pagination, you can use pagination with infinite scrolling https://www.ag-grid.com/javascript-grid-infinite-scrolling/#pagination&gsc.tab=0

    0 讨论(0)
提交回复
热议问题