Angular JS Smart Table Filtered collection

自闭症网瘾萝莉.ら 提交于 2021-02-08 03:42:25

问题


Where is the filtered collection after filtered value in smart table.

the table is bound with rowCollection.

<table st-safe-src="rowCollection" st-table="displayed" class="table table-bordered">

and i have used a search filter:

<input type="text" id="regionFilter" st-search="region" />

after the result are filtered i still see all records in rowCollection


回答1:


You can create a directive to access the get the filtered Collection. For example:

HTML:

<table 
    st-table="displayedCollection" 
    st-safe-src="rowCollection" 
    on-filter="onFilter">

Javascript:

//
// Create a directive
//
angular.module("smart-table").directive('onFilter', function () {
    return {
        require: '^stTable',
        scope: {
            onFilter: '='
        },
        link: function (scope, element, attr, ctrl) {

            scope.$watch(function () {
                return ctrl.tableState().search;
            }, function (newValue, oldValue) {
                scope.onFilter(ctrl);
            }, true);
        }
    };
});

//
// In your controller
//
$scope.onFilter = function (stCtrl) {
    var filtered = stCtrl.getFilteredCollection();
}


来源:https://stackoverflow.com/questions/29194548/angular-js-smart-table-filtered-collection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!