0

Trying to update a table with sorted values using Lodash. I have found this answer, which I am trying to implement.

Demo plunker is here - outputting sorted values to console when you click on the 'Sort' button, but does not sort and update the table values (vm.resourceGridResources.Resources) afterwards?

Code:

var sorted = _.orderBy(results, ['Value'], ['asc']);

console.log(sorted);

//this part is not working...
var sortedCollection = _.sortBy(temp, function(item) {
    return sorted.indexOf(item.ResourceId);
});

vm.resourceGridResources.Resources = sortedCollection;

Please can you advise how to resolve?

Paolo B
  • 3,026
  • 5
  • 21
  • 43

1 Answers1

0

You're using .indexOf on array with objects. You can use findIndex from lodash:

_.findIndex(sorted, {ResourceId: item.ResourceId});
iofjuupasli
  • 3,818
  • 1
  • 16
  • 17