Reputation: 1521
I've made a plunker were you can sort the data from largest to lowest value, which is great, but when you uncheck the box it sorts alphabetically like so
function(a, b) { return d3.ascending(a.name, b.name); }
I have no idea what to replace this with so that it just return to it's initial state before you checked the box, any help would be appreciated!
Upvotes: 1
Views: 32
Reputation: 102174
First, create an array with the correct order of your name
s:
var sortIndex = data.map(function(d){ return d.name});
And then use it for sorting:
function(a, b) {
return sortIndex.indexOf(a.name) - sortIndex.indexOf(b.name);
}
Here is your updated plunker: https://plnkr.co/edit/SmpDOk7KYSvrM2ioUoxE?p=preview
Upvotes: 1