如何更改表格中的ajax排序参数?

问题描述 投票:0回答:3
如何更改表中的Ajax排序参数?目前,ajax排序参数为

params.sorters [0] ['field']Params.Sorters[0] ['dir']

我找不到有关如何自定义的解决方案,就像我想更改

params.sorters [0] ['field']进入“ orderby” 和 parrams.sorters [0] ['dir']进入“ dir” Edit: 我正在使用反应模式和Laravel作为后端

javascript reactjs tabulator
3个回答
2
投票
sort[0][field]=name&sort[0][dir]=asc

简化了
orderBy=name&dir=asc
ajaxURLGenerator
new Tabulator("#myTable", {
    autoColumns: true,
    ajaxURL: 'https://myserver.com/api/items',
    sortMode: 'remote',
    ajaxURLGenerator: function (url, config, params) {
      // Get ajaxURL
      let myUrl = url;
      
      // If sorting, then get the field name and direction
      if (params['sort'].length > 0) {
        let field = params['sort'][0]['field'];
        let dir = params['sort'][0]['dir'];
        myUrl += `&orderBy=${field}&dir=${dir}`;
      }
  
      // Return request URL
      return myUrl;
    }
  });

文档:

    http://tabulator.info/docs/5.3/sort#ajax-sort
  • http://tabulator.info/docs/5.3/page#remote-url

1
投票
sort

而不是

sorters
.
以下示例说明将排序参数('sort')更改为上一个键(sorters')。 以下是如何修改远程排序参数的要旨:

let myTable = new Tabulator(myTableRef, { placeholder: null, ajaxURL: myAjaxUrl, ajaxConfig: { method: "POST", headers: { "Content-type": "application/json; charset=utf-8", }, }, ajaxContentType: { headers: { 'Content-Type': 'application/json' }, body: function(url, config, params){ // Rewrite 'sort' to 'sorters' to accomodate legacy api expectations. if(params.hasOwnProperty('sort')){ Object.defineProperty(params, 'sorters', Object.getOwnPropertyDescriptor(params, 'sort')) delete params['sort'] } return JSON.stringify(params) } }, // remainder of table definition.

使用制表器的
ajaxContentType

body
指定一个函数来编写Ajax请求的正文。 如果存在排序参数,则需要修改参数。 最后,将params对象转换为json并将其返回为身体内容。

文档中隐藏在

0
投票
paginationDataSent

选项page,但我不确定它是否会按照您描述的方式工作。您必须进行一些实验。

alltherther,还有更多的工作,您可以编写自定义
sorters
以任何您想要的方式重写参数。
    
@olifolkerd。
我在2025年有同样的问题,我正在使用Tabulator版本6.3
我尝试使用datareceiveParams {“ sort [0] [field]“:“ sortby”},但它不起作用。
有更新吗?谢谢你
    

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.