Skip to content
This repository
Browse code

simple filterCallback in the options to delegate complex search to en…

…d users
  • Loading branch information...
commit 6bbf830da8772cdbe2ece9d8138c7c1e3c9dcb0e 1 parent 2d7706a
John Bender authored

Showing 1 changed file with 4 additions and 1 deletion. Show diff stats Hide diff stats

  1. 5  js/jquery.mobile.listview.filter.js
5  js/jquery.mobile.listview.filter.js
@@ -10,6 +10,9 @@
10 10
 $.mobile.listview.prototype.options.filter = false;
11 11
 $.mobile.listview.prototype.options.filterPlaceholder = "Filter items...";
12 12
 $.mobile.listview.prototype.options.filterTheme = "c";
  13
+$.mobile.listview.prototype.options.filterCallback = function( text, searchValue ){
  14
+	return text.toLowerCase().indexOf( searchValue ) === -1;
  15
+};
13 16
 
14 17
 $( ":jqmData(role='listview')" ).live( "listviewcreate", function() {
15 18
 
@@ -70,7 +73,7 @@ $( ":jqmData(role='listview')" ).live( "listviewcreate", function() {
70 73
 						// New bucket!
71 74
 						childItems = false;
72 75
 
73  
-					} else if ( itemtext.toLowerCase().indexOf( val ) === -1 ) {
  76
+					} else if ( listview.options.filterCallback( itemtext, val ) ) {
74 77
 
75 78
 						//mark to be hidden
76 79
 						item.toggleClass( "ui-filter-hidequeue" , true );

3 notes on commit 6bbf830

Kimmo Puputti

Is there a reason why returning a truthy value results in a hidden item and not vice versa?

This is just the opposite to what e.g. Python's builtin 'filter' function or Underscore.js' array filter does.

John Bender

@kpuputti,

Its a direct port of the original logic and it's certainly up for debate whether that's intuitive. Thanks for commenting.

[UPDATE] I'm going to put this on the list for our discussion this week. Its a small change that'll make this much more usable.

Kimmo Puputti

Thanks, I'll follow for possible updates.

Please sign in to comment.
Something went wrong with that request. Please try again.