AngularJS smart-table strange behavior with nested objects and st-search

落爺英雄遲暮 提交于 2019-12-01 06:02:15

As laurent said, you need to use a custom filter

Use st-set-filter to set your filter

<table st-table="displayedProducts" st-safe-src="products" st-set-filter="customFilter" class="table table-striped table-bordered table-hover">

In your module, define a custom filter

angular.module('myModule').filter('customFilter', ['$parse', function($parse) {
    return function(items, filters) {
        var itemsLeft = items.slice();

        Object.keys(filters).forEach(function(model) {
            var value = filters[model],
                getter = $parse(model);

            itemsLeft = itemsLeft.filter(function(item) {
                return getter(item) === value;
            });
        });

        return itemsLeft;
    };
}])

You need to use a copy of your collection, so instead of doing the direct assignment $scope.displayedProducts = $scope.products; you should do $scope.displayedProducts= $scope.displayedProducts.concat($scope.products);

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