API Docs for: 0.0.2
Show:

dataSource.CollectionSearch Class

Extends Core
Module: Canvas

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

Methods

and

(
  • search
)
dataSource.CollectionSearch chainable

AND search

Parameters:

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.CollectionSearch chainable

Start grouping search items together

branch

() endBranch.CollectionSearch chainable

Close group of search items.

Returns:

endBranch.CollectionSearch: this

clear

() dataSource.CollectionSearch chainable

Clear all search terms and search functions

deleteSearch

()

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

execute

() dataSource.CollectionSearch chainable

Execute a search based on current search terms

Example:

     // Assumes that ludo.get('collection') returns a dataSource.Collection 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

Returns:

hasData

() Boolean

Returns true when
- zero or more records are found in search result
Returns false when
- search result is undefined because no search has been executed or search has been deleted.

Returns:

hasSearchTokens

() Boolean

Returns true if search terms or search functions exists.

Returns:

or

(
  • search
)
dataSource.CollectionSearch chainable

OR search

Parameters:

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.

where

(
  • search
)
dataSource.CollectionSearch chainable

Start building a new search

Parameters:

Example:

     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 dataSource.Collection/execute 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.CollectionSearch chainable

Search for match in one of the items

Parameters:

Attributes

delay

Number

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

Default: 0

Example:

delay:0

index

Array

Columns in datasource to index for search

Events

deleteSearch

Search executed without any search terms