【问题标题】:bootstrap table, sorting columns with custom sorter based on row attribute引导表,使用基于行属性的自定义排序器对列进行排序
【发布时间】:2020-06-19 10:34:00
【问题描述】:

我正在使用“引导表”API:https://bootstrap-table.com/。 我遇到的问题是我的字段设置了属性:

{field: 'price', title: 'prices', sortable: true, sorter: "customSorter"}

通过扩展,我的自定义排序器看起来像这样:

function customSorter(fieldA, fieldB) {

}

我希望能够在 customSorter 函数中访问我的行属性,因为我希望我的某些行具有特定属性(例如,如果 row.important 设置为 true)出现在顶部无论如何。我已经看到您可以使用“引导数据表”访问那些,因为自定义排序器是这样的:

function customSorter(fieldA, fieldB, rowA, rowB) {

}

但我不想为此更改,因为代码已经很庞大了,有没有我不知道的技巧可以做到这一点?

【问题讨论】:

    标签: javascript bootstrap-table


    【解决方案1】:

    您可以使用rowA.<attribute> 轻松访问属性,例如rowA.important。 问题是,如果您检查该属性并在排序器上重新调整 1,它仅适用于 desc 排序。 原因是bootstrap-table内部否定了格式化程序排序的结果是asc。

    目前没有额外的参数来检查用户是按asc还是desc排序。 请在 bootstrap-table 存储库中打开一个问题,它将很快添加。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-05
      • 1970-01-01
      • 2013-03-23
      • 1970-01-01
      • 2012-04-08
      相关资源
      最近更新 更多