isotope - 'no results' message? [closed]
Asked Answered
R

1

9

I'm using the Isotope JS plugin (v2.0.1) from Metafizzy to filter a library of publications, and I am using more than one filter (e.g. publisher and industry). Is there a way to check if my combination of filters has resulted in zero results, and then show a corresponding message... something like "Sorry. No matching items found."

Ranunculus answered 4/11, 2011 at 10:38 Comment(0)
A
15
$container.isotope({ filter: '.your-filter' });

  if ( !$container.data('isotope').$filteredAtoms.length ) {
    $('.message-div').fadeIn('slow');
  } else {
    $('.message-div').fadeOut('fast');
  }

You could also use hide/show or a number of other effects instead of fadeIn and fadeOut depending on your effect.

Anecdotal answered 13/4, 2012 at 17:35 Comment(3)
Thanks for sharing this, in the version of Isotope I am using (v2.1.1) I actually had to do it with filterItems.length so it was: if ( !$('.izotope-container').data('isotope').filteredItems.length ) {Unreeve
You can also achieve the same using the 'arrangeCompleted' event. That event provides two parameters to the function: event and filteredItems. filteredItems will give you the number of items after applying the filter and finished all the animations. I think this is more accurate. $grid.on( 'arrangeComplete', function( event, filteredItems ) { if( filteredItems.length > 0 ) // hide message else // show message; });Refraction
This worked for me: var elems = $grid.isotope('getFilteredItemElements'); if ( !elems.length ) { $('.project__filter--msg').show(); } else { $('.project__filter--msg').hide(); }Jenijenica

© 2022 - 2024 — McMap. All rights reserved.