Change sort based on model condition

  • 1
  • Idea
  • Updated 3 years ago
  • (Edited)
I recently came upon an interesting requirement. Users wanted the ability to filter for items in the past and items in the future. But they wanted the sorting to change based on the filter the user chose. I was unable to find the option to change the sorting based on a filter or even to run a snippet after selecting a filter. I'm also unable to add a unique id to a filter (so I can target it via javascript.) Either way, here's the workaround I created in order to accomplish this.

There are some flaws with this approach, the main one being that if there are multiple dropdown filters this will target all of them and then change the sort. but in my case there is only a single dropdown.

Figured I'd post in case anyone else has a need for 

Here's the entire inline snippet.
(function(skuid){
var $ = skuid.$; var activateHandler = function(){ skuid.$("#table .nx-conditioncontainer .nx-actionselect-arrow").on("click", function() { setTimeout(function(){ skuid.$("#table .nx-conditioncontainer .nx-actionselect-dropdown .nx-actionselect-dropdown-item").on("mousedown" /* use mousedown because it happens before "click" */, function() { var text = $(this).text(), m = skuid.$M("model-name"); switch (text) { case "Upcoming" : m.orderByClause = "Date__c"; //change the sort to show closest to current date first. break; default: m.orderByClause = "Date__c DESC"; break; } }); }) }); }; $(document.body).one('pageload', activateHandler); skuid.events.subscribe("models.loaded", activateHandler); })(skuid);

Feel free to post thoughts/suggestions.
Photo of Mordechai

Mordechai

  • 968 Points 500 badge 2x thumb

Posted 3 years ago

  • 1

Be the first to post a reply!