Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    ListGrid.setShowRowNumbers display on/off

    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.

    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;
    	}
    }

    #2
    A manual call to refreshFields() is currently required here.

    Comment


      #3
      Adding refreshFields() didn't work as I expected.
      Code:
      	@Override
      	public void onClick(MenuItemClickEvent event)
      	{
      		SC.logWarn("numbering:" + getShowRowNumbers());
      		setShowRowNumbers(!getShowRowNumbers());
      		refreshFields();
      	}
      If a TestListGrid object initially has setShowRowNumbers(false), then when that object is setShowRowNumbers(true) and refreshFields() is called, two columns appear with row numbers (one normal and one with an empty header menu).

      Then when the object has setShowRowNumbers(false) and refreshFields() called, the row number column with the empty header menu goes away leaving the normal row number column. After that, the refreshFields() call changes nothing visible.

      The refreshFields() call does not seem to make an impact if the TestListGrid object is initially setShowRowNumbers(true).

      Comment


        #4
        We've added a fix in this area - please retest with an upcoming nightly build

        Comment


          #5
          Thank you for the fix. Confirmed in SC_SNAPSHOT-2011-06-13/PowerEdition.

          Comment

          Working...
          X