• angularjs中是否选择所有和$filter过滤orderBy排序


    HTML代码:

    <table class="table table-bordered table-list table-striped no-margin-bottom">
        <thead>
        <tr>
            <th>{{'column-name' | translate}}</th>
            <th width="100">{{'primary-key' | translate}}</th>
            <th width="100">{{'required' | translate}}</th>
            <th width="100">
                <md-checkbox class="no-margin-bottom" aria-label="checked"
                             ng-checked="table.AllColumnChecked"//设置全选按钮初始状态(双向绑定)
                             ng-click="$ctrl.checkedAllColumn(table)"></md-checkbox>
                {{'select-all' | translate}}
            </th>
        </tr>
        </thead>
        <tbody>
        <tr ng-repeat="column in table.Table.ListColumn | orderBy :'DisplayOrder'">
            <td>{{column | columnTranslateFilter}}</td>
            <td><span ng-if="column.IsPrimaryKey">{{'true' | translate}}</span></td>
            <td><span ng-if="column.IsRequired">{{'true' | translate}}</span></td>
            <td>
                <md-checkbox class="no-margin-bottom" aria-label="checked"
                             ng-checked="column.checked"
                             ng-disabled="column.IsPrimaryKey"
                             ng-click="$ctrl.checkedColumn(table,column)"></md-checkbox>
            </td>
        </tr>
        </tbody>
    </table>

    js代码:
    self.checkedAllColumn = function (table) {
        table.AllColumnChecked = !table.AllColumnChecked;
        if (table.AllColumnChecked) {
            table.Table.ListColumn.forEach(function (col) {
                col.checked = true;
            })
            table.ListColumn = $filter('orderBy')(table.Table.ListColumn, 'DisplayOrder'//排序条件);
        } else {
            table.Table.ListColumn.forEach(function (col) {
                col.checked = false;
            })
            table.ListColumn = [];
        }
    };

    全选:点击全选按钮时(checkedAllColumn),if语句中的条件变为true,则筛选所有列选项(table.Table.ListColumn)并更改状态为选中状态(col.checked = true;);
    取消全选时,if语句中的条件变为false,则跳转到else筛选所有列选项并取消选中状态;
    orderBy排序:js中$filter('oederBy')获取所有列选项并根据排序条件进行排序;html中用| orderBy :'排序条件'获取排序列表;
    ng-checked="table.AllColumnChecked"中table需要在<div>中用ng-repeat定义;
  • 相关阅读:
    python05-循环
    python03-列表
    python03 input
    python02-灭霸的选择
    python学习小记01--萌新的进化
    Linux—-软件安装
    linux-认识与分析日志
    Esxi遇到问题汇总。
    xx
    Pramp mock interview (4th practice): Matrix Spiral Print
  • 原文地址:https://www.cnblogs.com/ncloud/p/7544575.html
Copyright © 2020-2023  润新知