PDA

View Full Version : set list view selection model



reecegwt
14 Jan 2010, 3:59 PM
Hi,

How can i set the selection model on a list view.


I tried the following but didnt work.

this.productListsView = new ProductListsView(productListStore);
if(selectedProductList!=null)
{
ListViewSelectionModel<ProductList> selectionModel = new ListViewSelectionModel<ProductList>();
selectionModel.select(selectedProductList, false);
this.productListsView.setSelectionModel(selectionModel);

}

Any help is appreciated..

Thanks
reece

Arno.Nyhm
15 Jan 2010, 10:26 AM
a) maybe you need to assign the selection model before you select something
b) maybe you have to fill the list before you select this

try to place the mySelectionModel.select(xxxxx) stuff in a DeferredCommand.addCommand(new Command() or do it after the rendering of the widget.

terciofilho
16 Jan 2010, 9:07 AM
Why don't you do this:



this.productListsView.getSelectionModel().select(selectedProductList, false);


This will select "selectedProductList" in your "this.productListsView" List View.

Arno.Nyhm
18 Jan 2010, 8:10 AM
note. this only works if the store is already loaded:





productListStore.getLoader().addListener(Loader.Load, new Listener<LoadEvent>()
{
public void handleEvent(LoadEvent le)
{

this.productListsView.getSelectionModel().select(selectedProductList, false);
}
});

from here:
http://www.extjs.com/forum/showthread.php?p=427864#post427864

reecegwt
18 Jan 2010, 1:11 PM
Thank you very much.
I tried this and it worked

this.getStore().addStoreListener(new StoreListener<ProductList>(){

@Override
public void storeDataChanged(StoreEvent<ProductList> se)
{
// TODO Auto-generated method stub
super.storeDataChanged(se);
ProductListsListView.this.getSelectionModel().select(productList, false);
}

});

terciofilho
18 Jan 2010, 1:55 PM
FYI, DataChanged is called even if you remove/add a row, not only when the data is loaded, in this case, is better to use the Arno.Nyhm solution.