Search code examples
smartgwtrow-numberlistgrid

(Auto Fit All Columns) of ListGrid's Context Menu stretches the Row number in SmartGWT


I'm not sure whether this should be the expected behaviour or is a bug. When the Row Number column is set to be shown, selection of (Auto Fit All Columns) from context menu stretches the column to the end of the ListGrid.

I though there is an issue in our app but the ShowCase has (Grids > Appearance > Row Numbering) the same problem.

final ListGrid countryGrid = new ListGrid();  
countryGrid.setWidth(500);   
countryGrid.setHeight(224);  
countryGrid.setShowAllRecords(true);  
countryGrid.setShowRowNumbers(true);

If you change the width of a column before applying the Auto fit it behaves normally.

Has someone had the same issue ever?

Is there any workaround?


Solution

  • Without looking further at your code (for instance, other width and autofit related configurations applied to the list grid, field types and expected contents) it's difficult to know if this is expected behavior. Although I agree, by looking at the demo, that it is at least strange behavior.

    But this is what I do in my ListGrids to keep the row numbers at the size I want:

    // this field is created only as a way to define the row number field properties
    ListGridField rowNumberFieldProps = new ListGridField();
    rowNumberFieldProps.setWidth(50);
    rowNumberFieldProps.setCanAutoFitWidth(true);
    rowNumberFieldProps.setAutoFitWidthApproach(AutoFitWidthApproach.VALUE);
    grid.setRowNumberFieldProperties(rowNumberFieldProps);
    grid.setShowRowNumbers(true);
    

    Some notes:

    • Since I expect a lot of records to be displayed (and in consequence, large row numbers), I use a row number column width that fits properly my numbers (50 in my case).
    • Notice that setCanAutoFitWidth(false) will leave your row number field fixed in size, even when 'Auto Fit All Columns' is used. This is probably a good approach in your case. If you do that, you can simply remove the line with setAutoFitWidthApproach.
    • setCanAutoFitWidth(true) and setAutoFitWidthApproach help me control what happens when I use the 'Auto Fit All Columns' context menu. In my case I do want autofitting to apply to extend the column width when I have row numbers beyond 99.999 (not the most common case for me, but possible).