我发布这个参考这个以前的帖子 服务器端分页+过滤+使用WebAPI进行ng-grid排序,希望能够最终得出一个简单但有效的使用ng-grid和外部数据源的样本.到目前为止,我已经设法实现了外部分页和排序,但我遇到了过滤问题.
它看起来像NG网过滤选项filterText属性未绑定到视图.当我在ng-grid的过滤器文本中键入内容时,我的$ watch-ed函数不会被调用,因此我没有机会向服务器请求过滤数据.然而,当用于例如分页或排序时,相同的监视表达式工作正常.
通过挖掘一下,我发现这篇文章https://github.com/angular-ui/ng-grid/pull/456关于这个领域的一个错误,但目前尚不清楚这是否仍然是一个悬而未决的问题.有人可以帮忙吗?这是相关的JS代码片段:
var app = angular.module('MyApp', ['ngGrid']);
app.controller('MainController', ['$scope', '$http', function ($scope, $http) {
$scope.items = [];
$scope.filterOptions = {
filterText: "",
useExternalFilter: true
};
$scope.totalServerItems = 0;
$scope.pagingOptions = {
pageSizes: [25, 50, 100],
pageSize: 25,
currentPage: 1
};
$scope.sortOptions = {
// omitted for brevity...
};
$scope.gridOptions = {
data: "items",
columnDefs: [
{ field: "id", displayName: "ID", width: "60" },
{ field: "name", displayName: "Name", pinnable: true },
{ field: "age", displayName: "Age", width: "60" },
{ field: "isFemale", displayName: "F", width: "40" }
],
enablePaging: true,
enablePinning: true,
pagingOptions: $scope.pagingOptions,
filterOptions: $scope.filterOptions,
keepLastSelected: true,
multiSelect: false,
showColumnMenu: true,
showFilter: true,
showGroupPanel: true,
showFooter: true,
sortInfo: $scope.sortOptions,
totalServerItems: "totalServerItems",
useExternalSorting: true,
i18n: "en"
};
$scope.refresh = function() {
setTimeout(function () {
// call the server and get data into $scope.items...
}, 100);
};
// this WORKS
$scope.$watch('pagingOptions', function (newVal, oldVal) {
if (newVal !== oldVal) {
$scope.refresh();
}
}, true);
// this DOES NOT WORK: the function never gets called
$scope.$watch('filterOptions', function (newVal, oldVal) {
if (newVal !== oldVal) {
$scope.refresh();
}
}, true);
// this WORKS
$scope.$watch('sortOptions', function (newVal, oldVal) {
if (newVal !== oldVal) {
$scope.refresh();
}
}, true);
$scope.refresh();
}]);
Run Code Online (Sandbox Code Playgroud)
这可能有点迟了但迟到总比没有好:)
我通过直接绑定到gridOptions的filterText属性获得了成功,如下所示
$scope.$watch('gridOptions.$gridScope.filterText', function (newVal, oldVal) {
if (newVal !== oldVal) {
}
}, true);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3262 次 |
| 最近记录: |