San*_*ool 7 jquery cell handsontable
我有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
});
Run Code Online (Sandbox Code Playgroud)
我有一个复选框.当我单击复选框时,Due应将(第4列)的值填充到"已接收"(列).如果我取消选中它,那么Received应该是空白的,这与表onload相同.
我的工作如下:
$("#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'
});
});
}
});
Run Code Online (Sandbox Code Playgroud)
它工作正常.
但问题是,在检查checbox后,该列的值将填充到第5列.但是if I edit any cell from 5th column, then the entire column except editted cell gets refreshed and 5th column becomes blank..
我怎么能避免它.
请参考图片了解详细信息:
如何在编辑后避免刷新单元格?
出现问题的原因是,一旦我将行值更改为另一个值,我就需要更新数据数组。当我更改内容时,它只会在屏幕上发生变化。当我编辑单元格时,它将调用渲染函数,并且它将采用旧的数据数组,这就是它显示没有值的列的原因。
这是我的解决方案:
如果:
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
});
Run Code Online (Sandbox Code Playgroud)
在其他方面:
g.each(function(i, v) {
f.eq(i).text("");
data[i][3] = ""; //Need to update the array also
});
Run Code Online (Sandbox Code Playgroud)