Jquery 编辑后,除编辑单元格外,整个列都会刷新Handsontable
我有一个Jquery 编辑后,除编辑单元格外,整个列都会刷新Handsontable,jquery,cell,handsontable,Jquery,Cell,Handsontable,我有一个Handsontable,如下所示: ordertable = new Handsontable(container, { data: data, colHeaders: ['Customer', 'Mode', 'Remarks', 'Due', 'Recieved'], columns: [{ data: 2, readOnly: true }, { data: 6, type: 'aut
Handsontable
,如下所示:
ordertable = new Handsontable(container, {
data: data,
colHeaders: ['Customer', 'Mode', 'Remarks', 'Due', 'Recieved'],
columns: [{
data: 2,
readOnly: true
}, {
data: 6,
type: 'autocomplete',
source: collectionmethod,
validator: collectionmethod_validations,
strict: true
}, {
data: 5,
readOnly: false
}, {
data: 4,
readOnly: true,
type: 'numeric',
format: '0.00'
}, {
data: 3,
type: 'numeric',
format: '0.00',
validator: amt_validations,
allowInvalid: true
}],
minSpareRows: 0,
rowHeaders: true,
contextMenu: ['row_above', 'row_below', 'remove_row', 'undo', 'redo'],
colWidths: [150, 100, rest, 100, 100],
autoWrapRow: true,
autoWrapCol: true,
beforeRemoveRow: removerow_validation
});
$("#sel_prefill").click(function() {
if ($("#sel_prefill:checked").val()) {
var g = $('.htCore').find('tbody tr td:nth-child(5)'); //Due
var f = $('.htCore').find('tbody tr td:nth-child(6)') // Recieved
g.each(function(i, v) {
f.eq(i).text(g.eq(i).text());
$(v).css({
'text-align': 'right'
});
});
} else {
var g = $('.htCore').find('tbody tr td:nth-child(5)'); //Due
var f = $('.htCore').find('tbody tr td:nth-child(6)') // Recieved
g.each(function(i, v) {
f.eq(i).text("");
//$container.handsontable('setDataAtCell', 1, 4, 5);
$(v).css({
'text-align': 'right'
});
});
}
});
我有一个复选框。当我单击复选框时,Due
(第4列)的值应填充到“received”(列)。如果我取消选中它,那么收到的应该为空,这与表onload相同
我的工作如下:
ordertable = new Handsontable(container, {
data: data,
colHeaders: ['Customer', 'Mode', 'Remarks', 'Due', 'Recieved'],
columns: [{
data: 2,
readOnly: true
}, {
data: 6,
type: 'autocomplete',
source: collectionmethod,
validator: collectionmethod_validations,
strict: true
}, {
data: 5,
readOnly: false
}, {
data: 4,
readOnly: true,
type: 'numeric',
format: '0.00'
}, {
data: 3,
type: 'numeric',
format: '0.00',
validator: amt_validations,
allowInvalid: true
}],
minSpareRows: 0,
rowHeaders: true,
contextMenu: ['row_above', 'row_below', 'remove_row', 'undo', 'redo'],
colWidths: [150, 100, rest, 100, 100],
autoWrapRow: true,
autoWrapCol: true,
beforeRemoveRow: removerow_validation
});
$("#sel_prefill").click(function() {
if ($("#sel_prefill:checked").val()) {
var g = $('.htCore').find('tbody tr td:nth-child(5)'); //Due
var f = $('.htCore').find('tbody tr td:nth-child(6)') // Recieved
g.each(function(i, v) {
f.eq(i).text(g.eq(i).text());
$(v).css({
'text-align': 'right'
});
});
} else {
var g = $('.htCore').find('tbody tr td:nth-child(5)'); //Due
var f = $('.htCore').find('tbody tr td:nth-child(6)') // Recieved
g.each(function(i, v) {
f.eq(i).text("");
//$container.handsontable('setDataAtCell', 1, 4, 5);
$(v).css({
'text-align': 'right'
});
});
}
});
它工作得很好
但问题是,在检查checbox的值4之后,该列的值填充为5。但是如果我编辑第5列中的任何单元格,则除已编辑单元格外的整个列都将刷新,第5列将变为空白。
我怎样才能避免呢
请参阅图片以了解逐步的详细信息:
如何避免编辑后刷新单元格?出现此问题的原因是,一旦将行值更改为另一行值,我需要更新数据数组。当我改变内容时,它只会在屏幕上改变。当我编辑单元格时,它将调用render函数,它将使用旧的数据数组,这就是为什么它显示没有值的列
以下是我的解决方案:
如果:
g.each(function(i, v) {
f.eq(i).text(g.eq(i).text());
data[i][3] = g.eq(i).text(); //Need to update the array also
});
在其他方面:
g.each(function(i, v) {
f.eq(i).text("");
data[i][3] = ""; //Need to update the array also
});
我想你的问题是这个f.eq(i).text(“”)代码>@madalin ivascu ok buddy。那么我需要换成什么呢?你有什么建议?你能详细说明并作为答案发布吗?这将非常有帮助。@madalin ivascu这只是代码改进的一个例子。我不认为它会这样做,因为编辑后它根本没有调用那个函数。它调用一些可手持的内置函数。我需要修改它,使它能够处理我的问题。这就是所有与您的问题相关的代码吗?您描述的问题似乎更多地与“更改”事件有关,而不是“单击”,并且您只发布了与单击事件有关的代码。@127.0.0.1无论是单击还是更改,它只是一个独立的单选按钮。函数中仅定义了具有handsontable
的依赖项,您可以从问题中引用该依赖项。