PDA

View Full Version : Filter and query



pje
28 Sep 2006, 4:57 AM
Hi,

can u provide an example of how to use the filter and query?

jack.slocum
28 Sep 2006, 9:03 AM
Sure.

Both take the same type of object. The object should have properties matching the column indexes you want to filter/query.

Here are some examples:



// filter by regex
// filter the data to only include rows which start with "a" in column 1
dataModel.filter({1: /^a/i});

// only rows with "Foo" in column 2 (exact match)
dataModel.filter({2: "Foo"});

// filter the model using a function
// only dates in the future for column 3
function inFuture(dateValue){
return (dateValue.getTime() > new Date().getTime());
}
dataModel.filter({3: inFuture});

// filter by all 3
dataModel.filter({1: /^a/i, 2: "Foo", 3: inFuture});


Array query(<Object> spec, <Boolean> returnUnmatched)

Query takes the same type of object and returns the matched row indexes. If you pass true for returnUnmatched, it returns the indexes of the rows that don't match.

Jack