smart-table - 如何重置过滤器集合?

2023-12-26

Angular 和智能表新手..

此智能表设置可以正常工作并正确过滤,但尝试重置或清除过滤器不会重新过滤表。为什么不?

使用 ng-model 绑定更新输入是否不会触发 smart-table 正在寻找的监视?

Plunker 可以在这里找到:http://plnkr.co/edit/4os3oWeJtEtMfa89QoQd?p=preview http://plnkr.co/edit/4os3oWeJtEtMfa89QoQd?p=preview

Code:

        var actionQueue = [
            { Type: 'User Access Request', Description: 'test test test test test test test', DateRequested: '5/5/15' },
            { Type: 'User Access Request', Description: 'blah blah', DateRequested: '3/3/10' },
            { Type: 'Project Approval Request', Description: 'project needs approving', DateRequested: '1/1/08' }
        ];

        $scope.actionQueueCollection = actionQueue;


        $scope.predicates = [{ Name: 'All', Value: '' }, { Name: 'User Access Request', Value: 'User Access Request' }, { Name: 'Project Approval Request', Value: 'Project Approval Request' }];
        $scope.selectedPredicate = $scope.predicates[0];

        $scope.clearFilter = function () {
            $scope.selectedPredicate = $scope.predicates[0];
            $scope.searchFilter = '';

        }

Markup:

    <table st-table="actionQueueCollection" >
        <thead>
            <tr>
                <th>
                    <div>
                        <label class="col-sm-1 control-label" for="filterType">Filter: </label>
                        <div class="col-sm-8">
                            <select class="form-control input-sm" id="filterType" name="filterType" ng-model="selectedPredicate" ng-options="predicate.Name for predicate in predicates track by predicate.Value" st-search="Type"></select>
                        </div>
                    </div>
                </th>
                <th colspan="3">
                    <div class="form-horizontal form-group-sm">
                        <div class="input-group col-sm-12">
                            <input st-search placeholder="search" class="form-control input-sm" type="search" ng-model="searchFilter" />
                            <button type="button" class="btn-sm btn-default" ng-click="clearFilter()">CLEAR</button>
                        </div>
                    </div>
                </th>
            </tr>
            <tr>
                <th>Type</th>
                <th>Description</th>
                <th>Date Requested</th>
            </tr>
        </thead>
        <tbody>
            <tr ng-repeat="action in actionQueueCollection">
                <td>{{action.Type}}</td>
                <td>{{action.Description}}</td>
                <td>{{action.DateRequested}}</td>
            </tr>
        </tbody>
    </table>

几乎是一样的事情。 这样使用起来更容易一些

.directive("stResetSearch", function() {
         return {
                restrict: 'EA',
                require: '^stTable',
                link: function(scope, element, attrs, ctrl) {
                  return element.bind('click', function() {
                    return scope.$apply(function() {
                      var tableState;
                      tableState = ctrl.tableState();
                      tableState.search.predicateObject = {};
                      tableState.pagination.start = 0;
                      return ctrl.pipe();
                    });
                  });
                }
              };
    })

然后用法是这样的

<button type="button" st-reset-search>Clear Filters</button>

在这里找到:https://github.com/lorenzofox3/Smart-Table/issues/164 https://github.com/lorenzofox3/Smart-Table/issues/164

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

smart-table - 如何重置过滤器集合? 的相关文章

随机推荐