0

You can find a working example here.

You'll notice that all the top level sorts work, except for the sort by "First Name" or "Last Name"...

Here's a code snippet from what I've done so far...

  <div class="option-combo shape">
    <h3>By First Name or Last Name</h3>

    <ul id="sort-by" class="option-set clearfix" data-option-key="sortBy">
      <li><a href="#sortBy=original-order" data-option-value="original-order" class="selected" data>All Employees</a></li>
      <li><a href="#sortBy=first" data-option-value="first">First Name</a></li>
      <li><a href="#sortBy=last" data-option-value="last">Last Name</a></li>      
    </ul>

I've made some progress so far...

Currently, the code below is commented out. If I remove the comment, then I am able to sort, but only by last name. Additionally, when this is enabled, the other sorts will no longer work and I can't seem to make them cohesive.

<!-- Allows for sort by last name -->  
      var $optionSets = $('#options .option-set'),
          $optionLinks = $optionSets.find('a');

      $optionLinks.click(function(){
        var $this = $(this);
        // don't proceed if already selected
        if ( $this.hasClass('selected') ) {
          return false;
        }
        var $optionSet = $this.parents('.option-set');
        $optionSet.find('.selected').removeClass('selected');
        $this.addClass('selected');

        // make option object dynamically, i.e. { filter: '.my-filter-class' }
        var options = {},
            key = $optionSet.attr('data-option-key'),
            value = $this.attr('data-option-value');
        // parse 'false' as false boolean
        value = value === 'false' ? false : value;
        options[ key ] = value;
        if ( key === 'layoutMode' && typeof changeLayoutMode === 'function' ) {
          // changes in layout modes need extra logic
          changeLayoutMode( $this, options )
        } else {
          // otherwise, apply new options
          $container.isotope( options );
        }

        return false;
      });

Your assistance is greatly appreciated!

Millhorn
  • 2,953
  • 7
  • 39
  • 77

1 Answers1

0

I queried David DeSandro about this and he replied with the following...

I'm hoping to revise this and simplify it in a big overhaul coming in a couple months.

Now then! Looks like you just need to set up the click handler for the sorting. See Codepen to see exactly how it works...

// Alphabetical Sort
var $sortBy = $('#sort-by');

$sortBy.on( 'click', 'a', function( event ) {
  var $this = $(this);
  var sortName = $this.attr('data-option-value');
  $container.isotope({ sortBy: sortName }); 
  $sortBy.find('.selected').removeClass('selected');
  $this.addClass('selected');
});

Head's up - I changed the getSortData for first

first : function( $elem ) {
return $elem.find('.first').text();
},

I hope this puts you in the right direction.

Millhorn
  • 2,953
  • 7
  • 39
  • 77