tabulator - 有没有办法使用ajax在制表器中将第一行设置为列标题?
问题描述
我正在使用制表器Tabulator使用 ajax 加载表。
var table = new Tabulator("#example-table", {
ajaxURL:"http://www.getmydata.com/now", //ajax URL
autoColumns: true,
});
它可以完美加载,但不会将第一行加载为列标题。我需要将 autoColumns 设置为 true,因为 ajax 响应是动态的并且列会发生变化。但是,第一行始终是列标题。制表器没有选择第一行作为标题。
我找不到将第一行设置为标题的相关配置。
解决方案
如果您使用该autocolumns
选项,制表器将从第一行的数据属性名称中提取列名,而不是从第一行的字符串数组中提取。
例如,使用以下数据:
var tabledata = [
{id:1, name:"Oli Bob", age:"12", col:"red", dob:""},
{id:2, name:"Mary May", age:"1", col:"blue", dob:"14/05/1982"},
{id:3, name:"Christine Lobowski", age:"42", col:"green", dob:"22/05/1982"},
{id:4, name:"Brendon Philips", age:"125", col:"orange", dob:"01/08/1980"},
{id:5, name:"Margret Marmajuke", age:"16", col:"yellow", dob:"31/01/1999"},
];
你最终会得到 4 列标题为“name”、“age”、“col”和“dob”。
无论您打算如何使用它,都必须始终以这种对象数组格式向 Tabulator 提供数据。
如果您的服务器无法提供这种格式的数据,那么您可以使用ajaxResponse
回调从服务器获取传入数据,重新格式化它,然后以 Tabulator 期望的格式从函数中返回它:
var table = new Tabulator("#example-table", {
ajaxResponse:function(url, params, response){
//url - the URL of the request
//params - the parameters passed with the request
//response - the JSON object returned in the body of the response.
return response.tableData; //return the tableData property of a response json object
},
});
可以在 [Ajax 文档[(http://tabulator.info/docs/4.9/data#ajax)
推荐阅读
- jquery-ui - 我如何激活我的 jquery 手风琴,它不工作?
- symfony - 在树枝中调用实体的函数
- python - 排除包含字符正则表达式的字符串
- javascript - JavaScript - ] 在从数组中删除另一个元素后从第一个元素中删除
- python - 为 Pandas 数据框中的每个重复行附加值/索引
- android - 如何根据 android studio 中的微调器选择更改 imageview 视图?
- html - 如何调整 iframe youtube 视频的界面大小?
- java - 弹簧靴 2 | 非常基本的依赖注入@Autowired问题
- asp.net-core - .NET core 3.1 应用程序显示“处理程序“aspNetCore”在其模块列表中有一个错误模块“AspNetCoreModuleV2””
- c - 将字符串分配给结构时缺少字符