ludo.dataSource.JSONArraySearch

ludo.dataSource.


new ludo.dataSource.JSONArraySearch(config)

Class created dynamically by dataSource.JSONArray.
It is used to search and filter data in a collection.

Parameters:
Name Type Description
config object
Properties
Name Type Description
delay object

Delay in seconds between call to search and execution of search.
A delay is useful when using text fields to search. Default : 0

index Array

Columns in datasource to index for search

Source:
Fires:
  • ludo.dataSource.JSONArraySearch#event:initSearch Fired just before search starts
  • ludo.dataSource.JSONArraySearch#event:search Fired when search is finished
  • ludo.dataSource.JSONArraySearch#event:deleteSearch

Methods


and(search) → {dataSource.JSONArraySearch}

AND search

Parameters:
Name Type Description
search String | function
Source:
Returns:

this

Type
dataSource.JSONArraySearch
Example
var searcher = myDataSource.getSearcher();
		 var populationFn = function(record){
					return record.population > 1000000 ? true: false;
				}
		 searcher.where('Europe').and(populationFn).execute();
	 Finds all records where 'Europe' is in the text and population is greater than 1
	 million.

branch() → {dataSource.JSONArraySearch}

Start grouping search items together

Source:
Returns:

this

Type
dataSource.JSONArraySearch

branch() → {endBranch.CollectionSearch}

Close group of search items.

Source:
Returns:

this

Type
endBranch.CollectionSearch

clear() → {dataSource.JSONArraySearch}

Clear all search terms and search functions

Source:
Returns:

this

Type
dataSource.JSONArraySearch

deleteSearch()

Delete search terms/functions and dispose search result. This method will fire a deleteSearch event which
{{#crossLink "dataSource.JSONArray"}}{{/crossLink}} listens to. It will trigger an update of
views using the {{#crossLink "dataSource.JSONArray"}}{{/crossLink}} object as dataSource.

Source:

execute() → {dataSource.JSONArraySearch}

Execute a search based on current search terms

Source:
Returns:

this

Type
dataSource.JSONArraySearch
Example
// Assumes that ludo.get('collection') returns a {{#crossLink "dataSource.JSONArray"}}{{/crossLink}} object
		 var searcher = ludo.get('collection').getSearcher();
		 searcher.clear();
		 searcher.where('Oslo').or('Moscow');
		 searcher.execute();

getCount() → {Number}

Returns number of records in search result

Source:
Returns:
Type
Number

hasData() → {Boolean}

Returns true when

- zero or more records are found in search result<br>

Returns false when

  • search result is undefined because no search has been executed or search has been deleted.
Source:
Returns:
Type
Boolean

hasSearchTokens() → {Boolean}

Returns true if search terms or search functions exists.

Source:
Returns:
Type
Boolean

or(search) → {dataSource.JSONArraySearch}

OR search

Parameters:
Name Type Description
search String | function
Source:
Returns:

this

Type
dataSource.JSONArraySearch
Example
var searcher = myDataSource.getSearcher();
		 var populationFn = function(record){
					return record.population > 1000000 ? true: false;
				}
		 searcher.where('Europe').or(populationFn).execute();

	 Finds all records where 'Europe' is in the text or population is greater than 1
	 million.

execute a text search

Parameters:
Name Type Description
search String
Source:

where(search) → {dataSource.JSONArraySearch}

Start building a new search

Parameters:
Name Type Description
search String | function
Source:
Returns:

this

Type
dataSource.JSONArraySearch
Examples
var searcher = ludo.get('idOfDataSearch').getSearcher();
		 searcher.where('Portugal').or('Norway').execute();
	 will find all records where the search index matches 'Portugal' or 'Norway' (case insensitive).
	 By default, the entire record is indexed. Custom indexes can be created by defining
	 index using the "index" constructor attribute.
	 
searcher.where(function(record){
	 		return parseInt(record.price) < 100
	 	});
	 is example of a function search. On {{#crossLink "dataSource.JSONArray/execute"}}{{/crossLink}} this
	 function will be called for each record. It should return true if match is found, false otherwise.
	 The function above will return true for all records where the value of record.price is less than 100.

withIn(searches) → {dataSource.JSONArraySearch}

Search for match in one of the items

Parameters:
Name Type Description
searches Array
Source:
Returns:

this

Type
dataSource.JSONArraySearch