PDA

View Full Version : Newbie in need: Issue with grid filtering...



sk8boip
18 Jun 2009, 3:55 AM
I have a Ext grid with 2 columns, and above that I have a textfield that I use for filtering the grid. The problem is that the grid seems to not be filtering correctly, but rather removing everything from the grid. My code extract is as follows:



var onFilteringBeforeQuery = function(e) {
var value = textfield.getValue();
alert(value);

if (value.length == 0) {
DataStore.clearFilter();
}
else {
value = value.replace(/^\s+|\s+$/g, "");
if (value == "")
return;

DataStore.filterBy(function(r) {
valueArr = value.split(/\ +/);

for (var j = 0; j < valueArr.length; j++) {
re = new RegExp(Ext.escapeRe(valueArr[j]), "i");
keep = false;

for (var i = 0, items = quickMenuItems, len = items.length; i < len; i++) {
if (items[i].checked) {
if (re.test(r.data[items[i].text.toLowerCase()]) == true) {
keep = true;
}
}
}

if (!keep) {
return false;
}
}
return true;
});
}
};


I also have a keyup event:


textfield.on("keyup", onFilteringBeforeQuery);


Any clue what I'm doing wrong or neglecting? :-?

18 Jun 2009, 3:57 AM
save two lines and just return keep.

that said, you're going to have to debug your code. have you tried stepping through with firebug?

sk8boip
18 Jun 2009, 4:49 AM
I got it working. I had a referencing issue. The store i was filtering was looking for something that did not exist. I.E. in the previous code, i changed this


if (re.test(r.data[items[i].text.toLowerCase()]) == true) {to this


if (re.test(r.data[items[i].id.toLowerCase()]) == true) {and presto chango the filtering works.

Thank you very much for your input.

gotcha
23 Jul 2009, 12:42 PM
In the below code, when a cell is matched, I want to highlight that cell - I tried the following, but it doesn't work!!!

Please advise.



var onFilteringBeforeQuery = function(e) {
if (this.scope) {
var store = this.scope.store;
var value = searchBox.getValue();
if (value.length===0) {
store.clearFilter();
} else {
value = value.replace(/^\s+|\s+$/g, "");
if (value === "") {
return;
}
store.filterBy(function(r) {
valueArr = value.split(/\ +/);
for (var j=0; j<valueArr.length; j++) {
re = new RegExp(Ext.escapeRe(valueArr[j]), "i");
keep = false;
for (var i=0,items=quickMenuItems,len=items.length; i<len; i++){
if (items[i].checked) {
if (re.test(r.data[items[i].id])===true){
keep = true;
}
}
}
if (!keep){
return false;
// At this point - we know the cell which matches the SEARCH string - so, HIGHLIGHT that cell
var rowIdx = store.indexOf(store.getById(r.id));
var gridCl = grid.getView().getCell(rowIdx, i );
var gridEl = Ext.fly(gridCl);
gridEl.highlight();

}
}
return true;
});
}
}
};