|
#1
|
|||
|
|||
|
Hi,
Is there a simple way to programmatically set the selected index of a SelectItem? Currently I have (as I mentioned elsewhere before) a ListGrid and SelectItem bound to the same datasource. The only problem I'm having at the moment is that if the record that is selected in the SelectItem is removed from the ListGrid and hence the DataSource then the 'String' value for that record remains as the selected item in the SelectItem. The record itself, is of course removed so Code:
selectItem.getSelectedRecord() Code:
selectItem.getValue() What I would really like to happen is when a value is removed from the ListGrid, if it is the currently selected value in the SelectItem then the first (non-null) item of the SelectItem should be selected instead. Normally I would do this in Java with a call to Code:
setSelectedIndex(0) I am currently trying out various approaches to this within a DataArrivedHandler in the SelectItem where event.getData() returns the correct number of results. |
|
#2
|
|||
|
|||
|
I fixed the inherent problem with this code within the DataArrivedHandler:
Code:
public void onDataArrived(DataArrivedEvent event){
if(selectItem.getSelectedRecord() == null || !event.getData().contains(selectItem.getSelectedRecord())){
Record first = event.getData().first();
if(first != null)
selectItem.setValue(first.getAttributeAsString("Name"));
else
selectItem.setValue("");
}
}
Code:
selectItem.setValue(record.getAttributeAsString("Name"));
It seems somewhat counter-intuitive that the databound records are so separate from the values concerned in getValue() / setValue(). |
|
#3
|
|||
|
|||
|
Can you clarify what you mean here:
Quote:
If so can you show us a test case demonstrating this? |
|
#4
|
|||
|
|||
|
Ok, so it appears the problem here was that I had an asynchronous rpc call in an override of show() that called setValue() (correctly) but then when the data arrived, the DataArrivedHandler kicked in and overwrote that data with the first value in the list for each piece of data that came back.
It would be useful if I didn't have to use the DataArrivedHandler in the first place to work around what I believe to be a bug. I've written a standalone test case for this here: http://pastebin.com/h3PFHA4C. I tried to keep it as concise as possible. Use case to reproduce the bug: 1. Click 'show dialog' button. 2. Drag 2 or more values from the left ListGrid to the right. 3. Select a record in the SelectItem. 4. Select that same record in the right ListGrid 5. Click 'Remove' button. Result: Record is removed from the DataSource, the ListGrid and partially from the SelectItem but the selected 'String' value remains in the SelectItem until it is manually changed. |
![]() |
| Thread Tools | Search this Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Need a way to control logging outside war/log4j.isc.config.xml | maksymg | Smart GWT Technical Q&A | 9 | 7th Jan 2013 01:35 |
| how to refresh databound UI components (SelectItem), once data has changed | tmp_7 | Smart GWT Technical Q&A | 9 | 8th Oct 2010 05:45 |
| Treegrid - setting same value to multiple grids | ypoovil | Technical Q&A | 1 | 26th Aug 2010 08:14 |
| Different fields on two databound objects | Captain Jack | Technical Q&A | 1 | 10th Jun 2010 07:58 |
| Refreshing databound Treegrid/Tree | sriram123 | Technical Q&A | 2 | 3rd Apr 2008 12:55 |