You need to sign in to do that
Don't have an account?
Cannot read property 'setAttribute' of undefined
Hello,
I'm using the Lightning-tree-grid component to display some nested data. I've written a sort function which works well, but every so often I'll get the following message 'Cannot read property 'setAttribute' of undefined'.
When commenting out the assignment of newly sorted data to the bound data variable, I cannot reproduce the error, so I think the sort algorithm is good. I've searched high and low and come up empty-handed looking for a solution or explanation. Any help you could offer would be great.
Here so the block of code causing the problem.
I'm using the Lightning-tree-grid component to display some nested data. I've written a sort function which works well, but every so often I'll get the following message 'Cannot read property 'setAttribute' of undefined'.
When commenting out the assignment of newly sorted data to the bound data variable, I cannot reproduce the error, so I think the sort algorithm is good. I've searched high and low and come up empty-handed looking for a solution or explanation. Any help you could offer would be great.
Here so the block of code causing the problem.
sortData(fieldName, sortDirection, dataType) {
//function to return the value stored in the field
var key = a => a[fieldName];
var reverse = sortDirection === 'asc' ? 1 : -1;
this.tableBuffer = JSON.parse(JSON.stringify(this.tableData));
switch (dataType.toLowerCase()) {
//handle types sortable as text
case 'text':
this.tableBuffer.sort((a, b) => {
let valueA = key(a) ? key(a).toLowerCase() : '';
let valueB = key(b) ? key(b).toLowerCase() : '';
return reverse * ((valueA > valueB) - (valueB > valueA));
});
break;
//handle types sortable as date
case 'date':
case 'currency':
case 'boolean':
this.tableBuffer.sort((a, b) => {
let valueA = key(a);
let valueB = key(b);
return reverse * ((valueA > valueB) - (valueB > valueA));
});
break;
//do nothing for types not handled, they shouldn't be sortable anyway
default:
break;
}
this.tableData = this.tableBuffer;
}
Apex Code Development
Well, I guess all it takes sometimes is just asking someone else the question to figure out what the issue really was. It turns out my test data was bad. A readout of JSON data showed row Ids not set due to missing data in some older test data. I deleted those records and it's working great now. Those records were created before I made a change the makes sure that data is present. I'm sorry if I wasted anyone's time, and thank you if you started to dig into this.