Ag网格中枢轴表的服务器端分页
我的网格数据非常大,我想添加分页。
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在这里,发送到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.