【问题标题】:AngularJS Datatables sort on checked itemsAngularJS数据表对选中的项目进行排序
【发布时间】:2016-03-25 05:52:34
【问题描述】:

我正在使用 anguarljs 林数据表Lin Datatables
数据表很好用,搜索、排序也很好用,但是需要对选中项目的数据表进行排序。
例如,当用户选中复选框并希望根据选中的项目进行排序时,排序功能不起作用。

谁能建议如何根据复选框使用 Lin 数据表进行排序。
检查复选框状态的html代码是

    <td><input id="{{content.fileName}}" type="checkbox"
value="{{content.fileName}}" ng-model="content.isChecked"
ng-click="toggleSelection(content)" /></td>

【问题讨论】:

  • 我不知道该插件,但它似乎根据 td 元素的文本内容对表格进行排序,尽管带有复选框的 td 元素的文本内容始终是一个空字符串。恐怕您必须向 td 元素添加文本,例如&lt;span style="display:none"&gt;{{content.isChecked}}&lt;/span&gt;。让我知道这是否有效。
  • @sniels 不幸的是它不起作用。
  • 你能做个小提琴吗?
  • @sniels,谢谢我会成功的,一旦完成会通知你
  • @sniels 正如 davidkonrad 提到的,请看这个plunker

标签: jquery html angularjs sorting datatable


【解决方案1】:

您应该实现小的dom-checkbox 插件。它也适用于角度数据表:

$.fn.dataTable.ext.order['dom-checkbox'] = function  ( settings, col ) {
  return this.api().column( col, {order:'index'} ).nodes().map( function ( td, i ) {
    return $('input', td).prop('checked') ? '1' : '0';
  })
}

然后将# 列设置为使用dom-checkboxorderDataType

DTColumnBuilder
  .newColumn(1)  
  .withTitle('#')
  .withOption('orderDataType', 'dom-checkbox'),

在这里复制了你的场景 -> http://plnkr.co/edit/kXFzUmcjikUOQliqn02Z?p=preview

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-16
    • 2019-05-20
    • 1970-01-01
    • 2016-10-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多