I’m looking to write a comparator to sort my items in a list.
For items without an end year they should be at the top.
For items with an end year they should be next.
For items with the same end year the one with the lowest start year should be next.
Something I have so far
[item.get('end_year'), item.get('start_year')]
Test sceanrios first is end year second is start year (“” is present)
"", ""
"", 2012
"", 2011
2012, 2005
2012, 2008
2011, 2011
2010, 2005
Add a comaprator function to your collection that takes two models in a ‘sort’ function. This will maintain your collection in sorted order as models are added to it. Note that if you change the start_year or end_year of a single model, you will have to resort the collection manually.