lau*_*lga 9 filtering angularjs angular-ui-grid
如何在按钮单击时清除并刷新所有(一般Angular和内置UI-Grid)过滤器?
背景:我构建了一个使用UI-Grid的应用程序,并利用了内置的过滤功能.它还有一个用角度写的跨列搜索.
当前战斗我希望能够通过单击按钮清除和刷新我的过滤器.到目前为止,我已经能够实现这一点用于跨列搜索,但是没有成功实现它用于内置列过滤器(具有讽刺意味的是,我认为这将是简单的部分!).
关于问题的研究:
1)通过UI-Grid教程搜索...失败
2)看看提供的UI-Grid API ......部分成功!好像我认为我在"clearAllFilters"函数中找到了我正在寻找的东西(这里是源代码),但我无法弄清楚如何实现它,所以在第3步...
3)用Google搜索疯狂的实现演示/示例/帮助/提示/任何东西!?...失败
4)在Stack Overflow上寻求帮助:)
提前致谢.
hic*_*086 17
对不起,我没有看到ui grid的clearAllFilters()函数.所以它变得更简单.你可以这样做:
$scope.clearFilters = function() {
$scope.myGridApi.grid.clearAllFilters();
};
Run Code Online (Sandbox Code Playgroud)
你可以这样做:
//获取网格api
$scope.myGridOptions.onRegisterApi = function(gridApi) {
$scope.myGridApi=gridApi;
}
Run Code Online (Sandbox Code Playgroud)
您必须将此功能绑定到清除按钮:
$scope.clearFilters = function() {
var columns = $scope.myGridApi.grid.columns;
for (var i = 0; i < columns.length; i++) {
if (columns[i].enableFiltering) {
columns[i].filters[0].term='';
}
}
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12337 次 |
| 最近记录: |