PDA

View Full Version : FormPanel or Grid with combos - loading question



cirkovic
9 Dec 2010, 11:05 PM
For example there is a FormPanel with several dynamically added fields, of which several are ComboBox<ModelData> fields.

Stores of combo boxes are binded with large sets of data (several thousands) so i am not loading that data in advance but only do queries when user types few chars, which means that at the moment when i receive data for form stores of combo boxes are empty.

I'm wondering what is the best way to handle this situation, as things are now i extended Converter and there i'm checking if combo store is empty and if so i'm sending request to server to return required model.

If there is small number of combos it's not big problem but if i'm using grid for example there could potentially be few hundreds of requests sent to server. So, what do you think is the best way to do this?

sven
10 Dec 2010, 3:13 AM
I'm wondering what is the best way to handle this situation, as things are now i extended Converter and there i'm checking if combo store is empty and if so i'm sending request to server to return required model.

I dont understand why you extend Converter. Can you please explain in detail what you are doing and maybe also post some small testcase? Isnt this example doing what you are looking for: http://www.sencha.com/examples/explorer.html#advancedcombobox

cirkovic
10 Dec 2010, 5:54 AM
I can't post example right now (maybe later) but i'll try to explain better :)
I am using the kind of combo you pointed me in grids/forms and the situation is next:

I'm receiving data for grid's or form's Store with models like

objects=[{col1=value1, col2=value2, ...},...]

and I'm binding those values to grid/form and that part works fine.

Some of the cell editors/fields on grid/form are those advanced combos, so for example value2 which binds to col2/field2 (where col2/field2 is advanced combo) is some id (foreign key to other table, emplyeeID=2) which is a valueField of combo and I want to display a combo's displayField (employeeName="John Doe").

At a time I receive grid/form's data from server combo's Store is empty, so when FieldBinding (in case of forms but similarly goes for grids) calls onConvertModelValue(model.get(property)) it cannot return from combo's model corresponding value because data for combo's Store wasn't loaded.
(and model in combo's store, when loaded, are in format like employees=[{emplyeeID=2, emplyeeName="John Doe"}, {..}, ..])

So I extended Converter and in method convertModelValue(Object value) I check

if (value != null && comboBox.getStore().findModel(comboBox.getValueField(), value) == null)

if it's true then it means data wasn't loaded (combo's store is empty, which is default when form/grid is first time opened) so I call loader of combo's store with appropriate config to load that particular model.

As I sad, in case of form and small number of combos this is not much of an issue, but with grid, even if I have one combo as cell editor, if there are say hundred rows, and each could have (theoretically) different value in that column, that would mean a hundred additional requests to server just for a display of one grid.

I hope this could little clarify what I'm doing

cirkovic
10 Dec 2010, 6:09 AM
Just to add: even when I'm using ComboBox<ModelData> with relatively small store so I call load() up-front it happens that data for form/grid arrives before the data for combo so then I have a similar situation as with previous