我在AngularJs项目之一中使用https://www.ag-grid.com/,我的要求是在进行任何分组时禁用任何列的排序。
我知道我们可以sorting/filtering
使用以下配置在单列上禁用:
colDef.suppressMenu = true
colDef.suppressSorting = true <--- this i can set up while giving column definition
在这种情况下,我将按国家/地区并扩展爱尔兰国家/地区对网格进行分组,但是现在我不禁用任何参数的排序,并在删除分组属性时再次启用它。
Is there a way to achieve this, Please let me know and if any duplicate question already exists please add that in the comment section.
Thanks
Finally, I solved the problem :), adding answer so it might help others
Note: I am not relying on Ag-Grid grouping I am getting after grouped data from my backend so below details can change for guys depending on Ag-Grids only
Ag-Grid provides various event listener, one of which is columnRowGroupChanged
So I registered this listener :
vm.gridOptions.api.addEventListener("columnRowGroupChanged", vm.updateRowData);
Then in updateRowData
method where i am creating my headerRow which will be used by Ag-Grid after grouping, I am also configuring at that time whether to sort or not :
vm.updateRowData = function (groupedColumnInfo) {
/\
||
||
Column Information on which grouping has been done
............
............
// Some Processing to get required details and finally setting the header again
............
............
vm.headerData = {
headerName: groupingAttributeItem.label,
field: fieldName,
width: 150,
headerClass: 'groupable-header',
cellClass: 'groupable-cell p-xs',
key: groupingAttributeItem.key,
sort: (params.sortingInfo && params.sortingInfo.colId === groupingAttributeItem.key) ? params.sortingInfo.sort : '',
suppressSorting: groupedColId ? true : false <--- deciding factor
};
// *Deciding factor* line checks that if some grouping has been done
// if NO then don't suppress sort for that column otherwise enable sorting
}
Note: By default sorting is enabled on all columns so we have to explicitly disable it.
这只是我完整代码库的一小段,因此跳过了如何获取标签和其他内容。
希望它对某人有帮助。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句