从 Tabulator JSON 下载中排除已删除的列
Exclude deleted columns from Tabulator JSON download
我正在尝试通过 downloadReady 方法捕获制表符 table 的 JSON。然而,JSON 包含使用 table.deleteColumn() 删除的列。如何从导出的 JSON?
中排除这些列
// pseudocode:
// delete bind
$("#deleteColumn").click(function(){
table.deleteColumn(field);
});
// download bind
$("#download-json").click(function(){
table.download("json", "data.json");
});
var table = new Tabulator("#table, {
downloadReady:function(fileContents, blob){
$.post( "saveJson.php", {
json: fileContents
});
return false;
}
});
我希望 JSON 代表实际的 table 但它包含已删除的列。
那是你误用了下载功能
下载功能是为创建文件供用户下载而设计的。传递给该函数的数据是要在自定义下载器中使用的数据,包含所有行数据。
它不适用于发送 ajax 请求。
正确的解决方案是实现您自己的调用 getData 函数的函数,该函数将 return 数据来自 table,然后将该数据传递给 ajax 请求处理函数。
您需要遍历并从 trow 数据中过滤掉您不想要的任何属性。制表符将为您提供每一行中的所有数据
function sendData(){
var data = table.getData(true);
var columns = table.getColumns();
var filteredData = [];
data.forEach(function(row){
var outputRow = {};
columns.forEach(function(col){
var field = col.getField();
if(col.getVisibility()){
outputRow[field] = row[field];
}
});
filteredData.push(outputRow);
});
//send your data via ajax
$.post( "saveJson.php", {
json: filteredData
});
}
我正在尝试通过 downloadReady 方法捕获制表符 table 的 JSON。然而,JSON 包含使用 table.deleteColumn() 删除的列。如何从导出的 JSON?
中排除这些列// pseudocode:
// delete bind
$("#deleteColumn").click(function(){
table.deleteColumn(field);
});
// download bind
$("#download-json").click(function(){
table.download("json", "data.json");
});
var table = new Tabulator("#table, {
downloadReady:function(fileContents, blob){
$.post( "saveJson.php", {
json: fileContents
});
return false;
}
});
我希望 JSON 代表实际的 table 但它包含已删除的列。
那是你误用了下载功能
下载功能是为创建文件供用户下载而设计的。传递给该函数的数据是要在自定义下载器中使用的数据,包含所有行数据。
它不适用于发送 ajax 请求。
正确的解决方案是实现您自己的调用 getData 函数的函数,该函数将 return 数据来自 table,然后将该数据传递给 ajax 请求处理函数。
您需要遍历并从 trow 数据中过滤掉您不想要的任何属性。制表符将为您提供每一行中的所有数据
function sendData(){
var data = table.getData(true);
var columns = table.getColumns();
var filteredData = [];
data.forEach(function(row){
var outputRow = {};
columns.forEach(function(col){
var field = col.getField();
if(col.getVisibility()){
outputRow[field] = row[field];
}
});
filteredData.push(outputRow);
});
//send your data via ajax
$.post( "saveJson.php", {
json: filteredData
});
}