简体   繁体   English

ag-Grid服务器端分页事件

[英]ag-Grid server side pagination events

I would like to do server side pagination in my ag-Grid. 我想在我的ag-Grid中进行服务器端分页。 I have successfully implemented the grid and displayed specific data when first time page loads. 我已成功实现网格并在第一次加载页面时显示特定数据。 I have more than 5000 records in my table and every time when I hit next button I need to call server to get next records in my grid. 我的表中有超过5000条记录,每当我点击下一步按钮时,我需要调用服务器来获取网格中的下一条记录。 But, I don't know how to listen pagination events to make another http request. 但是,我不知道如何监听分页事件以发出另一个http请求。 My server doesn't get hit when I click next/previous button. 单击下一个/上一个按钮时,我的服务器不会被点击。

My Grid options: 我的网格选项:

this.gridOptions = <GridOptions>{};
    this.gridOptions = {

        enableServerSideSorting: true,
        enableServerSideFilter: true,
        enableSorting: true,
        enableFilter: true,
        enableColResize: true,
        rowSelection: 'single',
        rowDeselection: true,
        columnDefs: this.columnDefs,
        rowModelType: 'infinite',
        paginationPageSize: 35,
        maxConcurrentDatasourceRequests: 2,
        infiniteInitialRowCount: 1,
        getRowNodeId: (item: any) => {
            return item.id;
        },
        pagination: true,
        onGridReady: () => { this.gridOptions.api.sizeColumnsToFit(); },
        context: { componentParent: this },//to invoke the method of this(parent) component from child component,
        onRowClicked: (event: any) => { this.router.navigateByUrl(`/dataList/edit/${event.data.id}`); },
    };

Data source defination: 数据源定义:

let dataSource = {
        getRows: (params: any) => {
            setTimeout(() => {

                let dataAfterSortingAndFiltering = this.sortAndFilter(allOfTheData, params.sortModel, params.filterModel);
                let rowsThisPage = dataAfterSortingAndFiltering.slice(params.startRow, params.endRow);
                // if on or after the last page, work out the last row.
                let lastRow = -1;
                if (dataAfterSortingAndFiltering.length <= params.endRow) {
                    lastRow = dataAfterSortingAndFiltering.length;
                }

                params.successCallback(rowsThisPage, lastRow);
            }, 500);
        }
    };
    this.gridOptions.api.setDatasource(dataSource);

This is a note from Aggrid doc: 这是来自Aggrid doc的一条说明:

In v9.0 ag-Grid pagination changed from server side pagination to client side pagination. 在v9.0中,ag-Grid分页从服务器端分页变为客户端分页。 Server side pagination was then removed in v10.1. 然后在v10.1中删除了服务器端分页。 If you were doing server side pagination, we recommend moving to pagination with infinite scrolling as a way of migration to the new mechanism. 如果您正在进行服务器端分页,我们建议使用无限滚动作为迁移到新机制的方式进行分页。 If you were slicing manually the data in your Datasource to mimic pagination done in the browser only, we recommend that you use the default In Memory Row Model and set the row data as normal and then set grid property pagination=true. 如果您手动切割数据源中的数据以模拟仅在浏览器中完成的分页,我们建议您使用默认的内存行模型并将行数据设置为正常,然后设置grid property pagination = true。

I think you can listen to paginationChanged event and make api call then call setData. 我想你可以听paginationChanged事件并调用api调用然后调用setData。

Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM