• Travis Cucore 8
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
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.
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;
  }


 
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.
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;
  }