Home >Web Front-end >Layui Tutorial >The sorting problem of table data processed by layui table module

The sorting problem of table data processed by layui table module

尚
forward
2019-11-23 17:40:153891browse

The sorting problem of table data processed by layui table module

When using layui table, it will happen when the data format of a certain column is converted, or the 0/1 status is changed to yes/no, or the number is changed to star rating display. I encountered a problem. My table data was converted into other forms and sort:true was set at the same time. At this time, after clicking the sort button, the column data disappeared. How to solve it?

You only need to set the sort order of a target table and send the request to the server again.

table.on('sort(这里是table的id)', function(obj){ //注:tool是工具条事件名,test是table原始容器的属性 lay-filter="对应的值"
          //尽管我们的 table 自带排序功能,但并没有请求服务端。
          //有些时候,你可能需要根据当前排序的字段,重新向服务端发送请求,从而实现服务端排序,如:
          table.reload('这里是layui-table定义时候的elem', {
              initSort: obj //记录初始排序,如果不设的话,将无法标记表头的排序状态。 layui 2.1.1 新增参数
              ,where: { //请求参数(注意:这里面的参数可任意定义,并非下面固定的格式)
                  field: obj.field //排序字段
                  ,order: obj.type //排序方式
              }
          });
      });

Recommended: layui tutorial

The above is the detailed content of The sorting problem of table data processed by layui table module. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete