【问题标题】:Sort Table by the order of the Array not Alphabetical按数组的顺序排序表而不是按字母顺序
【发布时间】:2016-09-07 14:38:50
【问题描述】:

就像在提到的标题中一样,我想按数组的顺序而不是正常的方式对表格进行排序 -> 按字母顺序。

   This is the Array with the Constants.
    .constant("appConfig", {
        "status": [
            "In Work",
            "Review",
            "Again in Edit",
            "Finished"
        ]
    })
//in the html then the standard code for sorting atm Alphabetical
       <th>
        <a href="#" ng-click="sortType='Status.status';sortReverse = !sortReverse">
          Status
          <span ng-show="sortType == 'Status.status' && !sortReverse" class="fa fa-caret-down"></span>
          <span ng-show="sortType == 'Status.status' && sortReverse" class="fa fa-caret-up"></span>
        </a>
        <select class="form-control" ng-model="select.Status.status">
          <option value="">-- Select --</option>
          <option ng-repeat='status in $ctrl.aStatus' >{{status}}</option>
        </select>
      </th>
      <tr dir-paginate="t in $ctrl.getTasks() | filter:{name:k}| orderBy: sortType:sortReverse| filter:select|itemsPerPage: 10 as results">

    <td class="td-selects">
                  <span uib-tooltip="{{t.notice}}" tooltip-popup-delay='500'>
                  {{t.Status.status}}</span>
                </td>

所以它正在排序
再次在编辑中
完成
工作中
评论
和反向相同。但它应该在“Todo Chain”-> 就像在常量数组中一样。像这样
工作中
评论
再次在编辑中
完成
和反向。
我可以以某种方式将 $index 或其他东西添加到它的工作方式中吗?

【问题讨论】:

    标签: angularjs arrays sorting constants angularjs-orderby


    【解决方案1】:

    您能否创建一个plunker/fiddle 并发布相同的链接以便更好地理解?

    【讨论】:

    • 你应该把它作为评论
    • codepen.io/anon/pen/fjkcg 这不是我的代码,而是作为示例。如果您对名字 Colum 进行排序,则按字母顺序排序。我的愿望是,如果我点击排序,它应该像在数组中一样排序。例如 John->Frank->Sue //see at $scope.data in .js
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-12-22
    • 2019-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-05
    • 1970-01-01
    相关资源
    最近更新 更多