angular4-material-table icon indicating copy to clipboard operation
angular4-material-table copied to clipboard

Cannot overwrite row.currentData

Open filipkbt opened this issue 6 years ago • 1 comments

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?

filipkbt avatar Dec 18 '19 15:12 filipkbt

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

blavenie avatar May 12 '20 13:05 blavenie