bootstrap_table自定义排序方法

公司老项目使用的是bootstrap框架,表格使用的是bootstrap-table。当前有个需求,需要按照自定义方法来排序。

比如要求,某些数据固定排在头部,其他的则按照对应字段排序。

最新的bootstrap-table中有customSort方法。

解释:The custom sort function is executed instead of the built-in sort function, takes three parameters: 

  • sortName: the sort name.
  • sortOrder: the sort order.
  • data: the rows data.

但是,项目中使用的是1.9.1 没有此方法。

于是曲线救国,采用prepend方法,插入要固定的数据。

初始化table之后,和每次点击排序名称的时候,添加两行代码:

$(this.table).bootstrapTable("refreshOptions", {data: data}) // data, 正常排序的数据
$(this.table).bootstrapTable("prepend", topFixed); // topFixed, 要固定在顶部的数据

这样就可以把需要固定显示在顶部的数据固定了,后面的数据依然按照列名对用字段排序。

猜你喜欢

转载自www.cnblogs.com/xguoz/p/12599417.html