【问题标题】:How to use checkboxes to filter data in angular smart table?如何使用复选框过滤角度智能表中的数据?
【发布时间】:2017-08-22 18:08:05
【问题描述】:

我正在尝试使用复选框过滤数据,因为我只需要是或否选项。

    <div class="col-xs-3">
        <input type="checkbox" data-st-search="option1" checked>
    </div>
    <div class="col-xs-3">
        <input type="checkbox" data-st-search="option2" checked>
    </div>
    <div class="col-xs-3">
         <input type="checkbox" data-st-search="option3" checked>
    </div>
    <div class="col-xs-3">
         <input type="checkbox" data-st-search="option4" checked>
    </div>

它总是只发送最后一个

【问题讨论】:

    标签: javascript angularjs angular-ui-bootstrap smart-table


    【解决方案1】:

    Laurent 建议创建一个指令来处理Filtering with a checkbox 中的复选框。 我根据我的场景调整了他的方法并得到了以下结果:

    HTML:

    <div st-pipe="vm.FilterData" st-table="Data">
         <st-checkbox id="IdForClick" text="Text for Label" predicate="ModelName"></st-checkbox>
         <table>
         ...
         </table>
    </div>
    

    控制器:

    vm.FilterData= function (tableState) {
         console.log(tableState.search)
         //filter logic
    };
    

    指令:

    angular.module('App').directive('stCheckbox', function () {
        return {
            restrict: 'E',
            scope: {
                predicate: '@',
                id: '@',
                text: '@'
            },
            replace: 'true',
            require: '^stTable',
            template:
                    '<div class="checkbox checkbox-primary checkbox-inline" ng-click="stCheckChange()">' +
                    '<input type="checkbox" id="{{id}}" ng-model="sel" ng-checked="sel">' +
                    '<label for="{{id}}"> {{text}}</label>' +
                    '</div> ',
            link: function (scope, element, attr, ctrl) {
                scope.stCheckChange = function () {
                    scope.sel = !scope.sel;
                    ctrl.search(scope.sel, scope.predicate);
                };
            }
        };
    })
    

    结果:

    【讨论】:

      【解决方案2】:

      我解决了,但不是最漂亮的解决方案。

      <input type="checkbox"
             st-search="option1"
             value="{{modelOption1}}"
             ng-model="modelOption1"
             ng-true-value="true"
             ng-false-value="false"/>
      

      【讨论】:

        【解决方案3】:

        您可以使用带有require: '^stTable' 的指令,然后,当复选框模型更改时,使用table.search(value, scope.predicate);

        <input type="checkbox" data-st-search="option3" ng-true-value="'YES'" ng-false-value="'NO'" checked>
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2019-11-08
          • 2020-11-30
          • 2020-10-10
          • 2016-08-15
          • 2019-10-20
          • 1970-01-01
          • 2015-06-29
          • 2017-08-16
          相关资源
          最近更新 更多