Replies: 18 comments 3 replies
-
Hi @madoar |
Beta Was this translation helpful? Give feedback.
-
Thanks for the answer. |
Beta Was this translation helpful? Give feedback.
-
Yes, afterValidate is called for each cell (that has any validator, not for
If you want to validate cells after table initialization. You can call Do you need any other piece of information? |
Beta Was this translation helpful? Give feedback.
-
Hi thank you for your code samples! refreshData() {
if (this.hot != null) {
this.hot.destroy();
}
this.hot = new Handsontable(this.hotTable.nativeElement, {
data: this.excelService.processedData,
rowHeaders: true,
colHeaders: this.excelService.processedColumnNames,
contextMenu: true,
columns: this.excelService.processedValidators,
afterValidate: (isValid, value, row, prop, source) => {
if (!isValid) {
if (!this.invalidFields.has(row)) {
this.invalidFields.set(row, new Set<number>());
}
this.invalidFields.get(row).add(prop);
} else if (this.invalidFields.has(row)) {
this.invalidFields.get(row).delete(prop);
if (this.invalidFields.get(row).size == 0) {
this.invalidFields.delete(row);
}
}
},
afterRemoveRow: (index, amount) => {
console.log(this.invalidFields.size);
this.invalidFields.delete(index);
console.log("Deleted row: " + index);
console.log(this.invalidFields.size);
}
});
this.hot.validateCells();
}
hasInvalidElements(): boolean {
return this.invalidFields.size > 0;
} Because it will not be possible to remove columns in my applications I've added no hook for that. What I would like to have is a more elegant and short way to do this. Is there such a way, or is such a way planned for handsontable? |
Beta Was this translation helpful? Give feedback.
-
Hi @madoar |
Beta Was this translation helpful? Give feedback.
-
@AMBudnik interface InvalidField {
row: number,
column: number
}
private invalidFields = new Set<InvalidField>();
this.hot = new Handsontable(this.hotTable.nativeElement, {
data: this.excelService.processedData,
rowHeaders: true,
colHeaders: this.excelService.processedColumnNames,
contextMenu: true,
columns: this.excelService.processedValidators,
beforeValidate: (value, row, prop, source) => {
const column = this.hot.propToCol(prop);
this.invalidFields.forEach((value, index, set) => {
if (value.row == row && value.column == column) {
this.invalidFields.delete(value);
}
});
},
afterValidate: (isValid, value, row, prop, source) => {
if (!isValid) {
const column = this.hot.propToCol(prop);
this.invalidFields.add({ row: row, column: column });
}
},
afterRemoveRow: (index, amount) => {
const numberOfColumns = this.hot.countCols();
for (let row = index; row < index + amount; row++) {
this.invalidFields.forEach((value, index, set) => {
if (value.row == row) {
this.invalidFields.delete(value);
}
});
}
}
});
this.hot.validateCells();
}
hasInvalidElements(): boolean {
return this.invalidFields.size > 0;
} In addition to the fact, that I now only need a normal Set without a Map now, I'm now also able to get row and column information of invalid fields quite easily by querying the row and column attributes of the InvalidField objects inside the Set. I believe it would be quite nice and useful, if you could add a getInvalidFields() method to the Handsontable object, which the user can use to receive a list of all currently invalid fields, similar to what |
Beta Was this translation helpful? Give feedback.
-
Wow... that actually sounds like a great improvement @madoar |
Beta Was this translation helpful? Give feedback.
-
I'm moving all the improvement suggestions to our wiki section. Please feel free to leave any additional comments and reflections. Thanks in advance! |
Beta Was this translation helpful? Give feedback.
-
It would really help if there was a hook like |
Beta Was this translation helpful? Give feedback.
-
Hi @aaronbeall I am sure it can be a pain to check again and again all 300 x 500 cells. That's a lot. I hope that I will be able to update you as soon as possible but if not please check the ZenHub board |
Beta Was this translation helpful? Give feedback.
-
For anyone interested I implemented the solution @AMBudnik suggested above to use function getIsValid(): boolean {
const rowsCount = hotInstance.countRows();
for (let row = 0; row < rowsCount; row++) {
const metaCols = hotInstance.getCellMetaAtRow(row);
if (metaCols.some(col => !col.valid)) {
return false;
}
}
return true;
} |
Beta Was this translation helpful? Give feedback.
-
I would like to echo that a hook like |
Beta Was this translation helpful? Give feedback.
-
Hi @softwaremills |
Beta Was this translation helpful? Give feedback.
-
@aaronbeall, col.valid is not working for custom validator |
Beta Was this translation helpful? Give feedback.
-
This feature request is closed. It will be automatically reopened after we attach it to a milestone. |
Beta Was this translation helpful? Give feedback.
-
Hi. Closed issues rarely get new comments, so I hope that this issue will get more attention as a discussion. See you there for updates and new ideas. |
Beta Was this translation helpful? Give feedback.
-
Any update on this? It would be nice to have a hook like |
Beta Was this translation helpful? Give feedback.
-
Hi @KiddoV I don't have any updates yet, but have you tried any of the proposed solutions in this thread? |
Beta Was this translation helpful? Give feedback.
-
I'm currently writing an angular 2 webapp that uses handsontable to display the content of some previously loaded csv file.
On the same page as the handsontable I've added a "continue" button, which should lead the user to the next page after he reviewed the loaded table and when its content is valid. The validity of the content is checked via column validator methods which are passed to the handsontable.
To ensure that the "continue" button is clicked only after the content is valid I want to bind the hidden property of the button to a function that returns if the content of the table is valid.
My question is now if there is such a function that returns true if all fields are valid, and false if not, that I can bind to the hidden property of the button.
Beta Was this translation helpful? Give feedback.
All reactions