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?

1 Answer 1

0

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

_.findIndex(sorted, {ResourceId: item.ResourceId});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.