angular4-material-table
angular4-material-table copied to clipboard
Cannot overwrite row.currentData
Hi, I'm checking if any of properties in object contains '' (empty string) and i'm trying to override it with null value.
for (let key in row.currentData) {
if ((!row.currentData[key]) || (row.currentData[key] && (row.currentData[key].toString().trim() === '') {
row.currentData[key] = null;
}
}
but after all, when I debug row.currentData selected property still has value: '' instead of null. What's wrong?
To update data, you should use the validator (if any) :
// Partial update:
row.currentData = {key: value};
// Or equivalent
row.validator.patchValue({key: value});
// Full update (all keys):
row.validator.setValue(data);
This is because row.currentData can be a getter, when using reactive form validator. See https://github.com/irossimoline/angular4-material-table/blob/master/src/table-element-reactive-forms.ts#L13