I want to create a menu which is bound to a DataSource. The DataSource doesn't have a field named "id", "title" or "name"; which I read -can't remember where- are looked for to display its value in the MenuItem label.
I've tried to use setTitleField method and even specifying a ListGridField with DisplayField attribute set (commented below) but I have had no success. When I use the setTitleField method the labels in menu items are empty, when I set the ListGridField; labels have correct titles but the border and background of the menu is not shown. Any help is appreciated, thanks.
Menu
DataSource
Data (actions.json)
I'm using SmartGWT 2.4, Firefox 3.6.16, GWT 2.0.4, Eclipse Plugin, Eclipse Helios, Ubuntu 10.10
I've tried to use setTitleField method and even specifying a ListGridField with DisplayField attribute set (commented below) but I have had no success. When I use the setTitleField method the labels in menu items are empty, when I set the ListGridField; labels have correct titles but the border and background of the menu is not shown. Any help is appreciated, thanks.
Menu
Code:
MenuButton btnMenu=new MenuButton("Show Actions"); Menu mActions = new Menu(); mActions.setDataSource(ActionsDS.getInstance()); mActions.setTitleField("actionTitle"); // ListGridField fldName=new ListGridField("name"); // fldName.setDisplayField("actionTitle"); // fldName.setValueField("actionId"); mActions.setFields(fldName); mActions.addItemClickHandler(new ItemClickHandler() { public void onItemClick(ItemClickEvent event) { MenuItem item = event.getItem(); SC.say("You picked the \"" + item.getAttributeAsString("actionTitle") + "\" action."); } }); btnMenu.setMenu(mActions); btnMenu.draw();
Code:
public class ActionsDS extends DataSource { private static ActionsDS instance = null; public static ActionsDS getInstance() { if (instance == null) { instance = new ActionsDS("actionsDS"); } return instance; } public ActionsDS(String id) { setID(id); setRecordXPath("/response/data"); DataSourceTextField fldId = new DataSourceTextField("actionId"); fldId.setPrimaryKey(true); DataSourceTextField fldTitle = new DataSourceTextField("actionTitle"); setFields(fldId, fldTitle); setDataFormat(DSDataFormat.JSON); setDataURL(GWT.getModuleBaseURL()+"data/json/actions.json"); } }
Code:
{"response":{ "status":200, "data":[ {"actionId":"1","actionTitle":"Aprove"}, {"actionId":"2","actionTitle":"Reject"}, {"actionId":"3","actionTitle":"Route"} ], "endRow":2, "startRow":0, "totalRows":3 } }
Comment