tabulator - 如何在制表符移动行上触发事件
问题描述
使用最新的 Tabulator 版本 4.4。我需要触发一个事件,以便捕获有关从一个表移动到下一个表的行的信息。移动在浏览器中运行良好,但从来没有触发任何东西,至少我可以看到,它告诉我移动了什么。我试过了
rowMoved:function(row){
//row - row component
}
但它永远不会发生。我尝试了发送者和接收者。我有一张桌子,上面有所有可能的问题,还有一张只包含拖到它上面的特定问题。
var allquestions = new Tabulator("#allquestions", {
ajaxURL : "includes/retrievequestions.php?id=All",
rowMoved:function(row){
//row - row component
alert("row moved ");
},
height:"300px",
layout:"fitColumns",
pagination:"local",
movableRows:true,
movableRowsConnectedTables:"#thistemplatequestions",
placeholder:"No Data Set available",
paginationSize:40,
paginationSizeSelector:[100, 200, 500, 1000],
movableColumns:true,
columns:[
{title:"Question", field:"questiontext", sorter:"string", width:100, headerFilter:"input"},
{title:"Description", field:"questiondescription"},
{title:"Value", field:"questionvalue", align:"center", width:100},
],
});
var thistemplatequestions = new Tabulator("#thistemplatequestions", {
ajaxURL : "includes/retrievequestions.php?id="+$("#thisid").text(),
movableRowsConnectedTables:"#allquestions",
rowMoved:function(row){
//row - row component
alert("row moved ");
},
movableRowsReceiver: customReceiver,
height:"300px",
layout:"fitColumns",
pagination:"local",
placeholder:"No Data Set available",
paginationSize:40,
paginationSizeSelector:[100, 200, 500, 1000],
movableRowsReceiver: "insert", //add rows when dropped on the table.
columns:[
{title:"Question", field:"questiontext", sorter:"string"},
{title:"Description", field:"questiondescription" , headerFilter:"input"},
{title:"Value", field:"questionvalue", align:"center", width:100},
],
});
var customReceiver = function(fromRow, toRow, fromTable){
alert("customer receiver ");
//fromRow - the row component from the sending table
//toRow - the row component from the receiving table (if available)
//fromTable - the Tabulator object for the sending table
if(toRow){
toRow.update({"questiontext":fromRow.getData().questiontext});
return true;
}
return false;
}
也尝试了 customReciever 也没有运气。它从未触发过。
我确信它可以完成,我只是不知道怎么做。
非常感谢任何帮助。
解决方案
看起来您的制表符定义thistemplatequestions
具有重复的movableRowsReceiver
. 删除第二个 ( movableRowsReceiver: "insert", //add rows when dropped on the table.
),customReceiver
然后执行您的遗嘱。
编辑:
根据制表符文档:
注意:必须在两个表上启用可移动行选项才能将行从一个表移动到另一个表。
您似乎movableRows: true
在thistemplatequestions
制表符定义中丢失了。
这是基于您的代码片段,以及我为使工作正常进行的修改:
var thistemplatequestions = new Tabulator("#thistemplatequestions", {
...
movableRows:true,
movableRowsReceiver: customReceiver,
...
});
function customReceiver(fromRow, toRow, fromTable){
//fromRow - the row component from the sending table
//toRow - the row component from the receiving table (if available)
//fromTable - the Tabulator object for the sending table
console.log("New Row Received!");
this.table.addRow(fromRow.getData(), undefined, toRow);
return true;
}
推荐阅读
- python - 在 Discord.py 中找不到我刚刚创建的角色 - 为什么?
- javascript - A: Discord.js v12+ 频道未定义
- amazon-web-services - 从 AWS SES Javascript v3 开发工具包发送电子邮件时,我可以包含显示名称吗?
- java - appscan期间jsp中的Validation.required错误
- node.js - 在带有 WHM 和 cpanel 的 Gen4 VPS Linux 4 CPU 上运行 nodejs
- flutter - 应用程序被杀死时收到通知(Flutter)
- html - Mac 设备中的 iframe 高度问题
- azure-devops - 如何在 Azure Devops 的 SonarQube 中结合 MsBuild 和 Javascript 项目?
- sql - SSMS 查询比较两个值
- sql-server-2008-r2 - SQL Server 2008R2 复制数据库不复制安全