PDA

View Full Version : filter store according to surrounding records



ShatyUT
18 May 2010, 1:28 PM
Hi All-

I think there must be a way to do this but I can't seem to get it. I have an EditorGridPanel with 2 columns. The first is not editable and shows the text of a question. The second has a Combo as the editor and is used to answer the question...each editor in the column has the same 4 responses.

Each question has a 'priority' as one of the values in the associated Record. The 'priority' is a value of 1, 2, or 3. Initially I filter the store so that the only rows displayed have record.get('priority') == 1. Next, if the user chooses "YES" as an answer to a question and that question has priority == 2 questions immediately following it, I want to show those questions. Conversely, if the answer is "NO" those questions should be hidden again.

I am trying to use the grid.getStore().filterBy(function(rec,id)) route to accomplish this but I don't think I can get the previous/next rows. I can't seem to figure out what the logic may be to accomplish this. I apologize if this looks like I'm trying to get you to do my work for me. I am just hoping there is a better way to accomplish the filtering that I haven't seen yet.

Thanks for taking a look!

FYI, here is the current code that gets called when the user selects an answer in one of the comboboxes:


if (cb.getValue("YES")) {
// Check for priority=2 questions below this one and show them
var sm = questionGrid.getSelectionModel();
// Get Record object for question that is being answered
var questionRec = sm.selection.record;
var store = questionGrid.getStore();
// Try to get next question with priority = 1 (answered question may be last question)
// Because priority=2 should already be filtered, the next priority=1 question should be next right now
var nextQuestionRec;
if (store.getCount() >= idx + 1)
nextQuestionRec = store.getAt(idx+1);
// Call function on each record using the 2 question records above to unfilter all questions between them
// This is where I am getting stuck
store.filterBy(function(rec, id) {
if (rec.get('priority') == 1)
return true;
else {
var startIdx = store.indexOf(questionRec);
var endIdx = -1;
if (Ext.isDefined(nextQuestionRec))
// Still returns next index since questions are filtered
endIdx = store.indexOf(nextQuestionRec);
return false;
}
});
}

ShatyUT
18 May 2010, 2:18 PM
I decided to scrap the filtering and just apply the x-hidden class to each row that should hide and then remove it when necessary. This is working for me.