Reputation: 1706
I have a handsontable structure as follows:
var container = document.getElementById('tableorder');
ordertable = new Handsontable(container, {
data: data,
colHeaders: ['Pdct', 'Notes', 'Qty', 'FQty', 'Fd Qty'],
columns: [
{data: 4, readOnly: false, type: 'autocomplete', source: prodnames, validator: product_validations, strict: true},
{data: 11, readOnly: false},
{data: 6, readOnly: false, type: 'numeric', format: '0.000', validator: qty_validations, allowInvalid: true},
{data: 18, readOnly: true, type: 'numeric', format: '0.000'},
{data: 19, readOnly: false, type: 'numeric', format: '0.000', validator: forward_validations, allowInvalid: true}
],
minSpareRows: 1,
rowHeaders: true,
contextMenu: ['row_above', 'row_below', 'remove_row', 'undo', 'redo'],
colWidths: [250, rest, 100, 100, 100],
autoWrapRow: true,
autoWrapCol: true,
beforeRemoveRow: removerow_validation
});
Onchange of column Fd Qty as follows:
function forward_validations(value, callback) {
var curdatatable = ordertable.getSourceData();
if(value.toString().trim()==""){
curdatatable[this.row][19] = 0;->not working
// curdatatable[this.row][18] = 0;->working perfectly
callback(true);
}
}
What I am doing is If the onchange value is blank then the same column ie, 19th. Needs to be changed to 0
In here the cell value needs to be changed and the onchange function happening cell is the same.
curdatatable[this.row][19] = 0;
-> not working
but if I try
curdatatable[this.row][18] = 0;
-> Working
Why it is happening like this?
How can change the value of cell if the onchange event happens on the same cell itself which is need to be altered?
Upvotes: 1
Views: 5295
Reputation: 1067
You're not really using an onchange event, you're using the validator function. Try using beforeChange instead.
beforeChange: function(changes, source) {
// changes is a 2d array like [[row, prop, oldVal, newVal], ...]
if (changes[0][1] == 19 && changes[0][3].toString().trim() == "") {
changes[0][3] = 0;
}
return changes;
}
Note you may need to loop through changes
to handle when you change multiple cells at once (like copy and paste.)
Upvotes: 2