使用 UI 网格进行服务器端过滤
server side filtering with UI grid
ui grid 提供了默认过滤,使用 gridOptions 中的 enableFiltering: false 启用。我没有使用此默认过滤,而是使用在过滤框中输入的文本用于多列,将过滤器发送到 serevr 并取回数据。我试过使用 filterOptions 但 $scope.$watch('filterOptions', function (newVal, oldVal) {
if (newVal !== oldVal) {
$scope.getPagedDataAsync($scope.gridOptions.$gridScope.filterText);
}
}, true);
永远不会被调用。感谢您的帮助。
有几种不同的方法可以做到这一点。在网格选项的 onRegisterApi 中,您可以这样做:
onRegisterApi: function(gridApi) {
gridApi.core.on.filterChanged($scope,
function(rowEntity, colDef, newValue, oldValue) {
// check which filter value changed and do something
// to get the value from a filter in column X you can do
gridApi.grid.columns[X].filters[0]
}
);
}
您还可以在每个单元格上设置一个过滤器对象。也许收集您希望过滤的各种列,然后在每个单元格上放置一个过滤器对象。每当发生变化时,您将拥有所需的所有值,并且您可以在 "condition" 中创建一个函数,调用它来进行过滤。
filter: { type: xxx, condition: $scope.myCustomFilter }
$scope.myCustomFilter = function(searchTerm, callValue) {
// check your various conditions here and return true/false
}
ui grid 提供了默认过滤,使用 gridOptions 中的 enableFiltering: false 启用。我没有使用此默认过滤,而是使用在过滤框中输入的文本用于多列,将过滤器发送到 serevr 并取回数据。我试过使用 filterOptions 但 $scope.$watch('filterOptions', function (newVal, oldVal) {
if (newVal !== oldVal) {
$scope.getPagedDataAsync($scope.gridOptions.$gridScope.filterText);
}
}, true);
永远不会被调用。感谢您的帮助。
有几种不同的方法可以做到这一点。在网格选项的 onRegisterApi 中,您可以这样做:
onRegisterApi: function(gridApi) {
gridApi.core.on.filterChanged($scope,
function(rowEntity, colDef, newValue, oldValue) {
// check which filter value changed and do something
// to get the value from a filter in column X you can do
gridApi.grid.columns[X].filters[0]
}
);
}
您还可以在每个单元格上设置一个过滤器对象。也许收集您希望过滤的各种列,然后在每个单元格上放置一个过滤器对象。每当发生变化时,您将拥有所需的所有值,并且您可以在 "condition" 中创建一个函数,调用它来进行过滤。
filter: { type: xxx, condition: $scope.myCustomFilter }
$scope.myCustomFilter = function(searchTerm, callValue) {
// check your various conditions here and return true/false
}