Ag网格中枢轴表的服务器端分页

发布于 2025-01-23 00:12:41 字数 2890 浏览 0 评论 0原文

我的网格数据非常大,我想添加分页。


const columnDefs = [
{
 field: 'athlete',
 minWidth: 200,
 enableRowGroup: true,
 enablePivot: true,
},
{
 field: 'age',
 enableValue: true,
},
{
 field: 'country',
 minWidth: 200,
 enableRowGroup: true,
 enablePivot: true,
 headerValueGetter: countryHeaderValueGetter,
},
{
 field: 'year',
 enableRowGroup: true,
 enablePivot: true,
},
{
 field: 'date',
 minWidth: 180,
 enableRowGroup: true,
 enablePivot: true,
},
{
 field: 'sport',
 minWidth: 200,
 enableRowGroup: true,
 enablePivot: true,
},
{
 field: 'gold',
 hide: true,
 enableValue: true,
 toolPanelClass: 'tp-gold',
},
{
 field: 'silver',
 hide: true,
 enableValue: true,
 toolPanelClass: ['tp-silver'],
},
{
 field: 'bronze',
 hide: true,
 enableValue: true,
 toolPanelClass: function (params) {
   return 'tp-bronze';
 },
},
{
 headerName: 'Total',
 field: 'totalAgg',
 valueGetter:
   'node.group ? data.totalAgg : data.gold + data.silver + data.bronze',
},
];

const gridOptions = {
columnDefs: columnDefs,
defaultColDef: {
 flex: 1,
 minWidth: 100,
 sortable: true,
 filter: true,
},  pagination: true, 
             rowModelType: 'infinite',
            
             cacheBlockSize: 100, // you can have your custom page size
             paginationPageSize: 100,
sideBar: {
             toolPanels: [
               {
                 id: 'columns',
                 labelDefault: 'Columns',
                 labelKey: 'columns',
                 iconKey: 'columns',
                 toolPanel: 'agColumnsToolPanel',
               },
             ],
             defaultToolPanel: 'columns',
           },
rowGroupPanelShow: 'always',
};


function countryHeaderValueGetter(params) {
switch (params.location) {
 case 'csv':
   return 'CSV Country';
 case 'clipboard':
   return 'CLIP Country';
 case 'columnToolPanel':
   return 'TP Country';
 case 'columnDrop':
   return 'CD Country';
 case 'header':
   return 'H Country';
 default:
   return 'Should never happen!';
}
}

// setup the grid after the page has finished loading
document.addEventListener('DOMContentLoaded', function () {
var gridDiv = document.querySelector('#myGrid');
new agGrid.Grid(gridDiv, gridOptions);
const dataSource = {
             rowCount: undefined, // behave as infinite scroll
             getRows: function (params) {
                var lastRow=-1;
                  fetch('https://www.ag-grid.com/example-assets/olympic-winners.json')
 .then((response) => response.json())
 .then((data) => {var data1=data.splice(params.start,100);params.successCallback(data1, lastRow) ;console.log(data,'data')});
                                       
                
             },
           };            
         gridOptions.api.setDatasource(dataSource);
         

});

但是,我不知道有什么问题,或者不知道有什么问题,或者有可能在服务器端的分页中 添加了分页,但我想添加分页。当我选择最小值或最大或计数数据时,我正在获取行数据,但在尝试部分时没有汇总数据。谁能说我错了。提前致谢

i have aggrid table with pivot mode true.since my grid data is very large i would like to add pagination.but pagination is added successfully with my below code


const columnDefs = [
{
 field: 'athlete',
 minWidth: 200,
 enableRowGroup: true,
 enablePivot: true,
},
{
 field: 'age',
 enableValue: true,
},
{
 field: 'country',
 minWidth: 200,
 enableRowGroup: true,
 enablePivot: true,
 headerValueGetter: countryHeaderValueGetter,
},
{
 field: 'year',
 enableRowGroup: true,
 enablePivot: true,
},
{
 field: 'date',
 minWidth: 180,
 enableRowGroup: true,
 enablePivot: true,
},
{
 field: 'sport',
 minWidth: 200,
 enableRowGroup: true,
 enablePivot: true,
},
{
 field: 'gold',
 hide: true,
 enableValue: true,
 toolPanelClass: 'tp-gold',
},
{
 field: 'silver',
 hide: true,
 enableValue: true,
 toolPanelClass: ['tp-silver'],
},
{
 field: 'bronze',
 hide: true,
 enableValue: true,
 toolPanelClass: function (params) {
   return 'tp-bronze';
 },
},
{
 headerName: 'Total',
 field: 'totalAgg',
 valueGetter:
   'node.group ? data.totalAgg : data.gold + data.silver + data.bronze',
},
];

const gridOptions = {
columnDefs: columnDefs,
defaultColDef: {
 flex: 1,
 minWidth: 100,
 sortable: true,
 filter: true,
},  pagination: true, 
             rowModelType: 'infinite',
            
             cacheBlockSize: 100, // you can have your custom page size
             paginationPageSize: 100,
sideBar: {
             toolPanels: [
               {
                 id: 'columns',
                 labelDefault: 'Columns',
                 labelKey: 'columns',
                 iconKey: 'columns',
                 toolPanel: 'agColumnsToolPanel',
               },
             ],
             defaultToolPanel: 'columns',
           },
rowGroupPanelShow: 'always',
};


function countryHeaderValueGetter(params) {
switch (params.location) {
 case 'csv':
   return 'CSV Country';
 case 'clipboard':
   return 'CLIP Country';
 case 'columnToolPanel':
   return 'TP Country';
 case 'columnDrop':
   return 'CD Country';
 case 'header':
   return 'H Country';
 default:
   return 'Should never happen!';
}
}

// setup the grid after the page has finished loading
document.addEventListener('DOMContentLoaded', function () {
var gridDiv = document.querySelector('#myGrid');
new agGrid.Grid(gridDiv, gridOptions);
const dataSource = {
             rowCount: undefined, // behave as infinite scroll
             getRows: function (params) {
                var lastRow=-1;
                  fetch('https://www.ag-grid.com/example-assets/olympic-winners.json')
 .then((response) => response.json())
 .then((data) => {var data1=data.splice(params.start,100);params.successCallback(data1, lastRow) ;console.log(data,'data')});
                                       
                
             },
           };            
         gridOptions.api.setDatasource(dataSource);
         

});

but I do not know what is wrong or is it possible to have server side pagination in aggrid or not .while trying I am getting row data but data is not aggregated when i choose min or max or count data is not changing in values section. Can anyone say where i am wrong. Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

当梦初醒 2025-01-30 00:12:41

在这里,发送到AG网格本身的数据包含100个记录。因此,只有在我们必须将整个数据集提供给Ag网格的情况下,它才能执行聚合。

Here the data being sent to AG Grid itself contains 100 records. Hence it can only perform aggregation for that if we have to provide the whole data set to AG Grid.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文