如何解决制表器可移动行 - rowPositioning() 在移动到组顶部时不更新放在组标题上
首先,感谢您迄今为止为 Tabulator 所做的出色工作 - 我一直在一个副项目中使用它,目的是在这些天的一个实际项目中使用它。我想说我是一名中级 Tabulator 用户/程序员,我发现可能是一个错误,但很高兴被证明是错误的。
问题:
当通过点击和拖动移动行时,当行移动到组的开头(通过拖放组标题)时,行定位 row.getPosition()
返回不正确的行值。我已经设置了下面链接的 JS 小提琴来演示这种行为。在此示例中,您可以通过将“Mary”行之一拖动到蓝色组的顶部来重现错误。表数据似乎没有随着更改而更新。
我尝试了变通方法,但找不到,这对我的目的很重要,因为我将行顺序存储在数据库中以重新加载页面。
预期行为:
通过在组标题上拖放将行移动到组顶部时,会导致正确的行定位 row.getPosition()
。
先谢谢你!
解决方法
我相信我已经回答了我自己的问题。我将在 Github 页面上报告错误。简而言之,我已经解决了对 Tabulator.js 中的 moveRowInArray 函数的微小更改。
第二个调整在技术上改变了预期的行为,因为它将行添加到组的前面,尽管这在我看来效果更好并且与第一个柚木兼容。但是可以重写以保留推送而不是狗屎,我敢肯定。
第 4105 行
RowManager.prototype._moveRowInArray = function (rows,from,to,after) {
var fromIndex,toIndex,start,end;
if (from !== to) {
fromIndex = rows.indexOf(from);
if (fromIndex > -1) {
rows.splice(fromIndex,1);
toIndex = rows.indexOf(to);
//////////////////////////////////////// jarb99 edit below
if (to.type == "group" && after) {
// splice above first row of group
toIndex = rows.indexOf(to.rows[0]);
after = false
}
//////////////////////////////////////// jarb99 edit above
if (toIndex > -1) {
if (after) {
rows.splice(toIndex + 1,from);
} else {
rows.splice(toIndex,from);
}
} else {
rows.splice(fromIndex,from);
}
}
//restyle rows
if (rows === this.getDisplayRows()) {
start = fromIndex < toIndex ? fromIndex : toIndex;
end = toIndex > fromIndex ? toIndex : fromIndex + 1;
for (var _i4 = start; _i4 <= end; _i4++) {
if (rows[_i4]) {
this.styleRow(rows[_i4],_i4);
}
}
}
}
};
第 20082 行
Group.prototype.insertRow = function (row,after) {
var data = this.conformRowData({});
row.updateData(data);
var toIndex = this.rows.indexOf(to);
if (toIndex > -1) {
if (after) {
this.rows.splice(toIndex + 1,row);
} else {
this.rows.splice(toIndex,row);
}
} else {
if (after) {
// this.rows.push(row); // jarb99
this.rows.unshift(row); // jarb99
} else {
this.rows.unshift(row);
}
}
row.modules.group = this;
this.generateGroupHeaderContents();
if (this.groupManager.table.modExists("columnCalcs") && this.groupManager.table.options.columnCalcs != "table") {
this.groupManager.table.modules.columnCalcs.recalcGroup(this);
}
this.groupManager.updateGroupRows(true);
};
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。