PDA

View Full Version : apply filter to combobox store- works 2nd time



lkasdorf
4 Apr 2008, 10:55 AM
Here is what I'm doing.

I create a combobox at load time. Its store is loaded from disk via proxy.

I create a formpanel at loadtime which contains the combobox.

I call a function that applies a filter to the store used by the combobox. Then, it shows the window.

The combobox shows the unfiltered list of values (even though firebug shows that the store only contains the filtered data).

I close the window and open it again. The combobox shows the filtered store this time.

I have attempted to get at the view object of the store, but it doesn't seem to exist.

I just wonder when the combobox gets a snapshot of the store for displaying?

By the way, my initial structure used lazy construction of the formpanel and the combobox, but this only worked the first time. The second time, the combobox was empty. This was a topic that I posted earlier this week.

I'll post code soon.


Comboboxes just always seem to give me fits...

devnull
4 Apr 2008, 10:57 AM
I believe the combo does its initial query in the render event.

lkasdorf
4 Apr 2008, 2:17 PM
Here I am creating the 2 comboboxes and my window at load time.



var letterCombo = new Ext.form.ComboBox(
{
hiddenName:"formLetter"
,id:"letterComboId"
,fieldLabel:"Choose a Letter"
,store: dsLetter
,mode:'local'
,displayField:'name'
,valueField: 'formletterId'
,emptyText: "Please select a letter"
,triggerAction:'all'
,width:200
,forceSelection:true
,listeners: {select:function(thisCombo, letterRec, idx)
{
loadEmailBody(letterRec, null);
}}
,baseCls:"margin:20px"
});

var absCombo = new Ext.form.ComboBox(
{
hiddenName:"countyStateAbs"
,id:"abstractorComboId"
,fieldLabel:"Choose an Abstractor"
,store: dsAbsc
,mode:'local'
,displayField:'countyStateAbs'
,valueField: 'abscountyId'
,triggerAction:'all'
,emptyText: "Please select an abstractor"
,width:300
,forceSelection:true
,listeners: {
select:function(thisCombo, absRec, idx)
{
var theForm = thisCombo.ownerCt.form;

theForm.setValues(absRec.data);
loadEmailBody(null, absRec);
}}

,baseCls:"margin:20px"
});



var absWin = new Ext.Window(
{
layout: 'form'
,modal: true
,shadow: true
,width: 535
,height: 490
,closeAction:'hide'
,plain: false
,style:"background-color:white;"
,items:
{ xtype:"form"
,id: 'absForm'
,header:false
,labelWidth:143
,style:"padding:10px;background-color:white;"
,border:false
,hideBorders:true

,items:
[
{xtype:"hidden", name:"abscountyId"}
,{xtype:"hidden", name:"transactionId", id:"transIdFldId"}
,{xtype:"hidden", name:"today", id:"todayFldId"}
,letterCombo
,absCombo

,{xtype: "textfield"
,id:'absEmailId'
,fieldLabel:"Abstractor Email Address"
,width: 200
,name:"orderEmail"
}

,{xtype: "textfield"
,id:'subjectFldId'
,fieldLabel:"Subject"
,width: 352
,name:"subject"
}

,{xtype:"textarea"
,name:"emailBody"
,id:"emailBodyId"
,hideLabel:true
,width:500
,height:300
}
]
}
,buttons:
[
{text:"Send Abstract Request"
,name:"sendEmail"
,tooltip:"This will send the email AND assign the selected abstractor to the current trasnaction."
,handler: function()
{
// we also need to save the abstractor setting here- this will happen in the php
var theForm = absWin.getComponent('absForm').form;
var valsObj = theForm.getValues(false); // return obj
Ext.Ajax.request(
{
waitMsg: 'Sending abstract request...'
,url: 'sendAbsEmail.php'
,params: valsObj
,method: 'POST'

,failure:function(response,options){
Ext.MessageBox.alert('Warning','Trouble sending abstractor email...');
}

,success:function(response,options){
absWin.hide();
// ds.commitChanges();
var responseData = Ext.util.JSON.decode(response.responseText);
Ext.example.msg('Email sent','Abstract request email sent and<br>abstractor selected for this transaction', "");
}
});
}
}
,{text:'Cancel'
,tooltip:"This will close this window without doing anything." ,handler:function(){ absWin.hide();} }
,{text:'Save'
,tooltip:"This will assign the selected abstractor to the current trasnaction<br>(and will NOT send the email)."
,handler:function(e){ absWin.hide();} }
]

,listeners:
{activate: function(theWin)
{
var theAbsCombo = Ext.getCmp("abstractorComboId");
theAbsCombo.setValue(dsAbsc.getAt(0).data.countyStateAbs);
// this does set the correct string in the
// field but does NOT fire the select event, even tho the docs say it does.
// on this combo, the displayfield and valuefield are both the same, and I am setting
// it to one of the values in the store, yet that value doesn't get selected

// experiment- theAbsCombo.select(0, true);
}}
}
);


Now, here is the function I call to display the window. In this function, I apply a filter to the store in hopes that the absCombo will show my filtered data.


function doAbstractWindow(grid, rowIndex, cellIndex, e)
{
if (gContextRecord.data.propCounty.length > 2)
{
dsAbsc.filter("countyState", gContextRecord.data.propCounty); // after doing this,
// firebug tells me that the store has the filtered data
var theAbsCombo = Ext.getCmp("abstractorComboId");
theAbsCombo.setValue(dsAbsc.getAt(0).data.countyStateAbs);
// this does set the correct string in the
// field but does NOT fire the select event, even tho it is supposed to.
// Perhaps this is because it is not rendered yet
// experimental -- theAbsCombo.select(0, true);
}
else
{
Ext.MessageBox.alert('Warning','You have not selected a county for the property yet. Please right-click on the borrower name to set the address and county.');
dsAbsc.clearFilter();
return;
}
absWin.setTitle("Abstractor Info for File " + gContextRecord.data.fileNumPrefix + gContextRecord.data.fileNum);

var theEditor = Ext.getCmp("emailBodyId");
theEditor.setValue("");

var theSubject = Ext.getCmp("subjectFldId");
theSubject.setValue(gContextRecord.data.fileNumPrefix + gContextRecord.data.fileNum + ", " +
gContextRecord.data.borrowerName);

if (!gLetterRec)
{
var theLetterCombo = Ext.getCmp("letterComboId");
gLetterRec = dsLetter.getAt(0);
theLetterCombo.setValue(gLetterRec.data.name);
}
absWin.show();
}



So- there are at least 2 things not working as I understand they should.

1. I filter the store for the absCombo before it is rendered- yet the first time it renders, it has the full data. Thereafter, it renders the correct data in the list

2. I would like to have the combo set to the correct thing upon appearance. In the absCombo I do something on the select event. If I setValue of the absCombo (with a valid choice from the datastore), it shows the correct thing, but does not actually select that item, and does not fire the select event. I have tried doing this selection both before I show the window, as well as on the activate event of the window. Same effect both ways.

Thanks to anyone who takes the time to look at this and respond.

Cheers

joku
4 Apr 2008, 3:15 PM
For the select method not firing the select event, the docs say to use setValue() and not select().
Here's an excerpt from the API documentation:

select( Number index, Boolean scrollIntoView ) : void
Select an item in the dropdown list by its numeric index in the list. This function does NOT cause the select event to fire. The store must be loaded and the list expanded for this function to work, otherwise use setValue.

lkasdorf
4 Apr 2008, 3:39 PM
Yes- in the code that I posted I am trying setValue and then there is an experimental select right after it. This was an experiment that I forgot to remove when I posted. The setValue did indeed set the value in the field, but didn't actually seelct anything or fire the event. I'm commenting out the select line in my post because it is a red herring.

Thanks for the reply!

scsi
6 Apr 2008, 9:41 PM
can you check if you have or not and "id" field in the combo
and waht if ever you comment the "id:" line
in my case i have a similar problem
1st time thze window appears it works
2nd time the combo only has 1 valus and i cna t change it
this ONLY occur with the "id:" explicitely set.
without id it works fine

i noticed too that the combo size was changed at the 2nd time the window is set on by show()

the problem is maybe something like the objects are not destroyed, or the wrong one is pointed....

denkoo
24 Apr 2008, 3:02 AM
Add only



lastQuery: '',



in definition of your editor column for you combo to filter

and all will be ok

micah.d.lamb
6 Feb 2009, 7:42 AM
I am having this same problem. I tried adding lastQuery: '' to the config of the column which holds the ComboBox I want filtered but it did not work.