Hello,
I have this code that can do a partial search on the first name or last name of any rows.
http://jsfiddle.net/EaNm4/520/
$(document).ready(function() {
var data = [
{firstName: 'Bob test', lastName: 'Kelso'},
{firstName: 'abc test', lastName: 'def'},
{firstName: 'toto test', lastName: 'tata'},
{firstName: 'foo test', lastName: 'var'},
];
$("#grid").kendoGrid({
dataSource: {data: data},
height: 350,
columns: ['firstName', 'lastName']
});
var searchOperator = function(items, filterValue) {
items = items.toLowerCase();
var searchText = $('#search').val().toLowerCase().split(/[\s,]+/);
if (searchText.length) {
var found = true;
for(var s in searchText) {
if (items.indexOf(searchText[s]) == -1) {
found = false;
break;
}
}
return found;
}
return true;
};
$('#search').on('change', function() {
var dataSource = $("#grid").data('kendoGrid').dataSource;
var searchText = $(this).val();
dataSource.filter({
logic:"or",
filters: [{
field: 'firstName',
operator: searchOperator
},{
field: 'lastName',
operator: searchOperator
}]
});
});
});
If you type "bob", "bob test", "bo te", or "kel" in the search box, the first rows will stay visible.
As long as you have a partial word, you will get the rows.
But if you search for a word in both cols, like "bob kelso" the row will not be display.
Is there a way to be able to search multiple fields at the same time, so "bob kelso" will display the first rows?
I was thinking maybe of a way that when the datasource is loaded, it will create a new field with all the data of all other rows, so when I do a search like that, I would simply search that field... is there a way to do something like that... or maybe you have a better suggestion?
Thank you