有没有办法使用 ajax 将第一行设置为制表符中的列标题?
Is there a way to set first row as column heading in tabulator using ajax?
我正在使用制表符 Tabulator 加载 table 使用 ajax。
var table = new Tabulator("#example-table", {
ajaxURL:"http://www.getmydata.com/now", //ajax URL
autoColumns: true,
});
它可以完美加载,但不会将第一行加载为列标题。我需要将 autoColumns 设置为 true,因为 ajax 响应是动态的并且列会发生变化。但是,第一行始终是列标题。制表符未选择第一行作为标题。
我找不到将第一行设置为 header 的相关配置。
如果您使用 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 列,标题为“姓名”、“年龄”、“col”和“出生日期”。
无论您打算如何使用它,都必须始终以这种 objects 格式的数组向 Tabulator 提供数据。
如果您的服务器无法提供这种格式的数据,那么您可以使用 ajaxResponse
回调从您的服务器获取传入数据,重新格式化,然后 return 从制表符期望的格式:
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)
中找到有关此内容的完整详细信息
我正在使用制表符 Tabulator 加载 table 使用 ajax。
var table = new Tabulator("#example-table", {
ajaxURL:"http://www.getmydata.com/now", //ajax URL
autoColumns: true,
});
它可以完美加载,但不会将第一行加载为列标题。我需要将 autoColumns 设置为 true,因为 ajax 响应是动态的并且列会发生变化。但是,第一行始终是列标题。制表符未选择第一行作为标题。
我找不到将第一行设置为 header 的相关配置。
如果您使用 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 列,标题为“姓名”、“年龄”、“col”和“出生日期”。
无论您打算如何使用它,都必须始终以这种 objects 格式的数组向 Tabulator 提供数据。
如果您的服务器无法提供这种格式的数据,那么您可以使用 ajaxResponse
回调从您的服务器获取传入数据,重新格式化,然后 return 从制表符期望的格式:
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)
中找到有关此内容的完整详细信息