我有一个客户在进行排序时特别不喜欢列标题中的下一个数字。这植根于UI-Grid的多重排序,该排序为每列赋予编号的优先级。有没有一种方法可以禁用多重排序以删除这些数字?我仍然想继续启用排序功能,但一次只能在一个列上。谢谢。
小智 5
我自己也遇到过这个问题。如果您仔细查看 ui0grid.js 代码,您会发现(此时)没有选项可以禁用它。ui-grid 的作者表示,他们欢迎在此线程中提出对此类功能的请求
但是,您想要的是修复,而不是承诺;-)
您可以发现在 sortChanged 方法中选择了多少个 sortColumn。
尝试这样的事情:
$scope.gridOptions.onRegisterApi = function(gridApi) {
$scope.gridApi = gridApi;
// Register a handler that is fired everytime someone changd the sort params.
$scope.gridApi.core.on.sortChanged($scope, function(grid, sortColumns) {
if (sortColumns.length > 1) {
// We have more than one sort. Kill the first one.
// If this works we'll only ever have 0, 1 or 2 sortColumns,
// and only ever 2 for the lifetime of this method.
var column = null;
for (var j = 0; j < grid.columns.length; j++) {
if (grid.columns[j].name === sortColumns[0].field) {
column = grid.columns[j];
break;
}
}
if (column) {
sortColumns[1].sort.priority = 1; // have to do this otherwise the priority keeps going up.
column.unsort();
}
}
});
};
Run Code Online (Sandbox Code Playgroud)
这与 ui-grid 的 3.0.0 版本背道而驰。
HTH
| 归档时间: |
|
| 查看次数: |
2156 次 |
| 最近记录: |