PDA

View Full Version : Editable Grid with Comboboxes



danic
10 Nov 2008, 7:29 AM
Hello, guys.

I recently started to work on an web application. Many parts of this application rely on a complex grid which I managed to develop from the existing one. The problem that I recently encountered is that I cannot use combo boxes that have an associated data model. I will give an example
- consider that you want to map a db table the has 3 columns: id, name and parent (where parent id an INT pointing to a record in a different table - for instance, a table with cities that has a country id)
- now, when I click on a cell representing the parent, I want to be able to open a combo box in which a country list will appear (this is easy)
- the combo box will contain objects of type Country(id, name)
- when a country is selected from the combo, I want the country id stored in the grid's model and the country name as cell text

Is this possible? Basically, the cell should be able to store an object of type Country(id, name) and use the data as follows: the value in the model = Country.id, the cell text = Country.name.

Thanks in advance.

Best regards,
Dani

gslender
10 Nov 2008, 1:17 PM
yep, this is possible - the data type would be custom and as long as you include a toString to display the name to the combo, it should work - I do this with a Frequency column (ie day,week,month) and did it with Enums to make it extra handy ;-)

danic
11 Nov 2008, 1:49 AM
Thanks for the answer, @gslender.

I managed to pull it off. In my case the problem is a little more delicate because of using dynamic data (not data contained in a prepopulated data structure - enum). The most important thing is to set the field.type (for that column) to point to a custom data structure.

Best regards,
Dani

richrdo
13 Nov 2008, 2:58 AM
Hi UFO lovers. I keep on seeing red dots crossing each other. I took some pictures, and it also shows a hover pod of some sort, but i dont have them on my PC. The pods were a bit like the picture up at the top. I thought I saw a human in the red light, but there has been no missing reports (as far as I know). But because I was so freaked out, my mind might of been tricking me. I see them alot so it can

danic
13 Nov 2008, 7:38 AM
Moving right along from UFOs...

Maybe I misunderstood this, but: the grid in GXT is not as flexible as it should. I will give a short example (I hope I am wrong): you want to create a simple editor grid to edit the following DB table: cities[id, name, state] where state is a foreign key to states[id, name]. Ok, for the id and the name of the state is easy. The tricky part is when you create a paging ComboBox editor to edit the state (foreign key). You want your paging combo to be populated with beans containing [id, name] - definition for a state created as a subclass of BaseModelData (for example). Ok, everything is fine so far. But, in order for this to work (and to have your data stored corectly in the grid's model) you need a PropertyEditor for the field that contains the ComboBox. In order for that PropertyEditor to work you would have to have ALL the data loaded (we can have 1000 states and a paging combobox which loads data on demand). What do we do in this case? Load the entire amount of data into the PropertyEditor? I don't think this is a good ideea..

Am I approaching this the wrong way?

Thanks a lot!

PS: It's a shame that such a great product has lacking documentation and a very poorly developed community...

Best regards,
Dani

danic
14 Nov 2008, 6:08 AM
Darrell, any thoughts on this one?

nannous
16 Jan 2009, 5:01 AM
Hello, guys.

I recently started to work on an web application. Many parts of this application rely on a complex grid which I managed to develop from the existing one. The problem that I recently encountered is that I cannot use combo boxes that have an associated data model. I will give an example
- consider that you want to map a db table the has 3 columns: id, name and parent (where parent id an INT pointing to a record in a different table - for instance, a table with cities that has a country id)
- now, when I click on a cell representing the parent, I want to be able to open a combo box in which a country list will appear (this is easy)
- the combo box will contain objects of type Country(id, name)
- when a country is selected from the combo, I want the country id stored in the grid's model and the country name as cell text

Is this possible? Basically, the cell should be able to store an object of type Country(id, name) and use the data as follows: the value in the model = Country.id, the cell text = Country.name.

Thanks in advance.

Best regards,
Dani

Did you find an answer for this problem ?
Do you have a sample code ?
Thanks

Michi_de
19 Jan 2009, 5:33 AM
Just add the .toString() method to the "Country"-Model.

sthamman
23 Jan 2009, 5:21 PM
You can achieve it by overriding preProcessValue() & postProcessValue() methods of CellEditor as shown below

editor = new CellEditor(field) {
@Override
public Object preProcessValue(Object name) {
if (name == null) {
return null;
}
String valueAttr = ((ComboBox)field).getValueField();
if (valueAttr == null)
valueAttr = "value";
return ((ComboBox)field).getStore().findModel(valueAttr,
name);
}

@Override
public Object postProcessValue(Object value) {
if (value == null) {
return null;
}
String valueAttr = ((ComboBox)field).getValueField();
if (valueAttr == null)
valueAttr = "value";
return ((RPCModelData)value).get(valueAttr);
}
};

Thanks,
Sreeni