I would like to share my experience regarding a contextmenu attached to a listgrid which is refreshed from server according to the row the user clicks.
First of all, the context:
* a ListGrid attached to a DataSource
* a Menu attached to another DataSource
* both DataSources are set with 'DSProtocol.POSTXML' and a servlet DataURL
To set a Menu content with xml data, I tried this tags:
To refresh data from server according to the row selected by the user, I tried to add a RowContextClickHandler to the ListGrid:
And to execute action depending on the MenuItem the user clicks, I tried to add a RecordClickHandler to the Menu:
*Beware*
- The line "listGrid.getContextMenu().filterData(criteria);" disable the ItemClickHandler which have to be replaced as we can by a RecordClickHandler.
- The line "listGrid.getContextMenu().filterData(criteria);" disable the possibility shown by the showcase to build a hierarchical Menu (http://www.smartclient.com/smartgwt/showcase/#menus_category_treebinding).
First of all, the context:
* a ListGrid attached to a DataSource
* a Menu attached to another DataSource
* both DataSources are set with 'DSProtocol.POSTXML' and a servlet DataURL
To set a Menu content with xml data, I tried this tags:
Code:
<List> <menuItem> <name>menu1</name> <icon>action/approve.png</icon> <title>Menu 1</title> </menuItem> <menuItem> <isSeparator>true</isSeparator> </menuItem> </List>
Code:
grid.addRowContextClickHandler(new RowContextClickHandler() { public void onRowContextClick(RowContextClickEvent event) { final ListGrid listGrid = (ListGrid) event.getSource(); Criteria criteria = new Criteria(); for(ListGridRecord rec : listGrid.getSelection()) criteria.addCriteria("ID", rec.getAttribute("ID")); listGrid.getContextMenu().filterData(criteria); } });
Code:
contextMenu.addRecordClickHandler(new RecordClickHandler() { public void onRecordClick(RecordClickEvent event) { execute(event.getRecord().getAttribute("title")); } });
- The line "listGrid.getContextMenu().filterData(criteria);" disable the ItemClickHandler which have to be replaced as we can by a RecordClickHandler.
- The line "listGrid.getContextMenu().filterData(criteria);" disable the possibility shown by the showcase to build a hierarchical Menu (http://www.smartclient.com/smartgwt/showcase/#menus_category_treebinding).