| David | Jones |
| Joe | Lincoln |
| David | Lincoln |
Only the third row should be returned, as it is the only one with a full match for all the keywords.
Thank you.
|
var val: any;
var refresh=false;
var removeQuery = false;
var valAssign = false;
// Grid’s actionBegin event function
function onActionBegin(args) {
if (args.requestType === "searching") {
// Default search operation is cancelled
args.cancel = true;
// Search string is split based on ‘,’
const text = args.searchString.split(',');
console.log(text);
let flag = true;
let predicate: Predicate;
if (this.searchSettings.key !== '') {
// Search string is maintained in global variable
val = args.searchString;
// Filter query is generated considering each split value as each column value
text.forEach((key, index) => {
var col = this.getColumns()[index];
if (flag) {
predicate = new Predicate(col.field, 'contains', key);
flag = false;
} else {
predicate = predicate.and(col.field, 'contains', key);
}
});
// Query is generated and assigned to Grid query property
this.query = new Query().where(predicate);
// Search value is emptied
this.searchSettings.key = '';
// Flag variables to differentiate operations
refresh = true;
valAssign = true;
removeQuery = true;
// Grid is refreshed
this.refresh();
}
}
if (refresh) {
refresh = false;
this.refresh();
} else if ((document.getElementById(this.element.id + '_searchbar') as HTMLInputElement).value === '' && args.requestType === "refresh" && removeQuery) {
// When search text box is emptied this condition will be executed
// Empty query is assigned to Grid query
this.query = new Query();
removeQuery = false;
this.refresh();
}
}
// Grid’s actionComplete event function
function onActionComplete(args) {
// On Grid refresh the stored search string is assigned to search box
if (args.requestType === 'refresh' && valAssign) {
(document.getElementById(this.element.id + '_searchbar') as HTMLInputElement).value = val;
valAssign = false;
}
} |
| Category Name | Product Name |
| Beverages | Chai |
| Beverages | Chang |
| Beverages | Chartreuse verte |
Allan Fife it would match a row containing the words Allan and Fife, regardless of the order or position that they appear in the table.All will match Allan.|
// Grid’s actionBegin event function
function onActionBegin(args) {
if (args.requestType === "searching") {
// Default search operation is cancelled
args.cancel = true;
// Search string is split based on ‘,’
// This can be modified as per your need
const text = args.searchString.split(',');
console.log(text);
let flag = true;
.
.
}
} |