I have extended the ListGrid class so that adds a menu item to toggle the display of row numbers. The problem I'm having is that while I can set showRowNumbers true/false, I cannot get the ListGrid to toggle the visibility of the rowNumber column. Any suggestions?
I am using SC_SNAPSHOT-2011-05-17/PowerEdition.
I am using SC_SNAPSHOT-2011-05-17/PowerEdition.
Code:
import com.smartgwt.client.util.SC; import com.smartgwt.client.widgets.grid.ListGrid; import com.smartgwt.client.widgets.menu.MenuItem; import com.smartgwt.client.widgets.menu.MenuItemSeparator; import com.smartgwt.client.widgets.menu.events.ClickHandler; import com.smartgwt.client.widgets.menu.events.MenuItemClickEvent; public class TestListGrid extends ListGrid { protected MenuItem[] getHeaderContextMenuItems(final Integer fieldNum) { final MenuItem[] items = super.getHeaderContextMenuItems(fieldNum); MenuItem lineNumberItem = new MenuItem("Toggle Row Numbering", "../images/row_num.png"); lineNumberItem.addClickHandler(new ClickHandler() { @Override public void onClick(MenuItemClickEvent event) { SC.logWarn("numbering:" + getShowRowNumbers()); setShowRowNumbers(!getShowRowNumbers()); } }); MenuItem[] newItems = new MenuItem[items.length + 2]; for (int i = 0; i < items.length; i++) { MenuItem item = items[i]; newItems[i] = item; } newItems[items.length] = new MenuItemSeparator(); newItems[items.length + 1] = lineNumberItem; return newItems; } }
Comment