我正在尝试从本地存储恢复表头顺序,但不适用于ajax响应中的头。
var table = new Tabulator("#example-table", {
placeholder: "No Data Available", //display message to user on empty table
movableColumns: true, //enable user movable columns
persistence: {
columns: true,
},
ajaxURL: "/ajax/showall", //ajax URL
persistenceWriterFunc: function (id, type, data) {
//id - tables persistence id
//type - type of data being persisted ("sort", "filter", "group", "page" or "columns")
//data - array or object of data
if (Array.isArray(data) && data.length) {
// array does not exist, is not an array, or is empty
// ⇒ do not attempt to process array
console.log('do not save empty array');
localStorage.setItem(id + "-" + type, JSON.stringify(data));
};
},
persistenceReaderFunc: function (id, type) {
//id - tables persistence id
//type - type of data being persisted ("sort", "filter", "group", "page" or "columns")
return data ? JSON.parse(data) : false;
},
ajaxResponse: function (url, params, response) {
this.setColumns(response.header);
return response.data;
}
});
有什么方法可以做到这一点?我试图使用tableBuilding: function()
等,但没有任何效果。我不想发送Ajax查询只是为了获得表头。
无需手动执行任何此操作,只要启用了持久性列选项,启用持久性模块,它将自动为您完成所有这些操作
var table = new Tabulator("#example-table", {
persistence:{
columns: true, //persist columns
}
});
请参阅Persistence Documentation了解更多信息。
只要您的ajax响应设置了列,它们就会自动更新本地存储选项。
[如果您要替换内置存储选项,则只需要使用persistenceWriterFunc和persistenceReaderFunc选项,该选项似乎没有出现,您需要在此处执行此操作] >