smart-table - how to reset filter collection?

若如初见. 提交于 2019-12-05 06:38:04

Pretty much the same thing. Usage is a little easier this way

.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();
                    });
                  });
                }
              };
    })

And then usage is like this

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

found here: https://github.com/lorenzofox3/Smart-Table/issues/164

So this is what I've come up with... not sure if its a good approach or not, but from what I gather I need to create a lot of directives to exert functionality over smart-table?

<button type="button" class="btn-sm btn-default" smart-table-reset="clearFilter()">

    .directive('smartTableReset', ['$parse', function ($parse) {
        return {
            restrict: 'A',
            require: '^stTable',
            link: function (scope, element, attr, ctrl) {
                var tableCtrl = ctrl;
                var fn = $parse(attr['smartTableReset']);

                element.on('click', function (event) {
                    ctrl.tableState().search = {};
                    tableCtrl.search('', '');
                    scope.$apply(function () {
                        fn(scope, {
                            $event: event
                        })
                    });
                });
            }
        };
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!