Skip to content Skip to sidebar Skip to footer

Angularjs Smart-table Strange Behavior With Nested Objects And St-search

I'm trying to implement the Smart Table module in my AngularJS app. I'd prefer this over some others mainly because the others seemed require a lot of boilerplate code in my contro

Solution 1:

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) {
    returnfunction(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;
    };
}])

Solution 2:

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);

Post a Comment for "Angularjs Smart-table Strange Behavior With Nested Objects And St-search"