Announcement

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

    ListGrid.sort (sortField, sortDirection) does not work

    When I call ListGrid.sort (), the ListGrid is not sorted.
    I noticed this in the following cases:
    1. The sortField is part of the ListGridRecord, but not added as a ListGridField to the ListGrid, or
    2. The sortField is part of the ListGridRecord, and added as a ListGridField to the ListGrid, but hidden

    Sorting seems to work ONLY if the field is displayed on the screen.
    Additionally, when sorting does not work, it seems that the ListGrid is sorted by the first visible column.
    See the attached picture for an example.

    This is the ListGrid method I am calling:
    Code:
    public native Boolean sort(String sortField, SortDirection sortDirection)
    Using
    SmartGWT 3.0
    GWT 2.3.0
    Firefox 6.0.2

    Code:
    import com.smartgwt.client.widgets.grid.ListGrid;
    import com.smartgwt.client.widgets.grid.ListGridField;
    import com.smartgwt.client.widgets.grid.ListGridRecord;
    import com.smartgwt.client.widgets.layout.VLayout;
    import com.smartgwt.client.widgets.IButton;
    import com.smartgwt.client.widgets.events.ClickHandler;
    import com.smartgwt.client.widgets.events.ClickEvent;
    import com.smartgwt.client.types.Autofit;
    import com.smartgwt.client.types.SelectionStyle;
    import com.smartgwt.client.types.GroupStartOpen;
    import com.smartgwt.client.types.SortDirection;
    
    import com.google.gwt.core.client.EntryPoint;
    
    public class TestListGridSort implements EntryPoint {
    
      /**
       * The EntryPoint interface
       */
      public void onModuleLoad () {
    
        // create ListGrid
        final ListGrid listGrid = new ListGrid ();
        listGrid.setShowAllRecords (false);
        listGrid.setAutoFetchData (false);
        listGrid.setCanEdit (false);
        listGrid.setAutoFitData (Autofit.BOTH);
        listGrid.setCanSort (true);
        listGrid.setSelectionType (SelectionStyle.SINGLE);     // allow only single-selection
    
        // by default, group by Today/Yesterday/Before Yesterday
        listGrid.setGroupStartOpen (GroupStartOpen.ALL);
        listGrid.setCanGroupBy (true);
        listGrid.setGroupByField ("group");
    
        // add fields
        final ListGridField groupField = new ListGridField ("group", "Group", 100);
        final ListGridField displayIndexField = new ListGridField ("displayIndex", "Display Index", 50);
        final ListGridField nameField = new ListGridField ("name", "Name", 150);
        listGrid.setFields (
          groupField,
          displayIndexField,
          nameField);
    
        // hide management columns
        // WARNING: if listGrid.hideField ("displayIndex"); is called, the sort () invocation below appears to do nothing 
        listGrid.hideField ("group");
        listGrid.hideField ("displayIndex");
    
        // add records
        {
          final ListGridRecord listGridRecord = new ListGridRecord ();
          listGridRecord.setAttribute ("group", "Group One");
          listGridRecord.setAttribute ("displayIndex", 400);
          listGridRecord.setAttribute ("name", "Name 1");
          listGrid.addData (listGridRecord);
        }
        
        {
          final ListGridRecord listGridRecord = new ListGridRecord ();
          listGridRecord.setAttribute ("group", "Group Two");
          listGridRecord.setAttribute ("displayIndex", 200);
          listGridRecord.setAttribute ("name", "Name 3");
          listGrid.addData (listGridRecord);
        }
        
        {
          final ListGridRecord listGridRecord = new ListGridRecord ();
          listGridRecord.setAttribute ("group", "Group One");
          listGridRecord.setAttribute ("displayIndex", 300);
          listGridRecord.setAttribute ("name", "Name 2");
          listGrid.addData (listGridRecord);
        }
        
        {
          final ListGridRecord listGridRecord = new ListGridRecord ();
          listGridRecord.setAttribute ("group", "Group Two");
          listGridRecord.setAttribute ("displayIndex", 100);
          listGridRecord.setAttribute ("name", "Name 4");
          listGrid.addData (listGridRecord);
        }
    
        // sort by name
        listGrid.sort ("displayIndex", SortDirection.ASCENDING);
        
        // add a button -- maybe sorting works after the ListGrid is displayed
        final IButton button = new IButton ();
        button.setTitle ("Sort by displayIndex");
        button.addClickHandler (new ClickHandler () {
          public void onClick (ClickEvent event) {
            listGrid.sort ("displayIndex", SortDirection.ASCENDING);
          }
        });
        
        // layout
        final VLayout layout = new VLayout ();
        layout.addMember (listGrid);
        layout.addMember (button);
        layout.show ();
      }
    }
    Is this by design?
    Should I open a bug?
    Any advice on how to get this to work?
    Attached Files

    #2
    Thanks for the report - we've fixed LG.sort() on hidden fields and those that exist only in the DS. Please see a nightly build after tomorrow for the fixes.

    Note, however, that LG.setSort() is more powerful than sort(), and sort() calls through to it anyway, so you should probably use setSort() directly.

    Comment


      #3
      I encountered a similar problem with group by. I cannot use group by on a hidden column.

      Code:
      ListGrid grid = new ListGrid();
      grid.setGroupStartOpen(GroupStartOpen.ALL);
      grid.setGroupByField("Sector");
      
      DataSourceField field = new DataSourceField("Sector", null, null);
      field.setHidden(true);

      Comment


        #4
        We've also now addressed this in 3.0p and 3.1d - see nightlies from tomorrow for the fix.

        Comment


          #5
          Hi,

          Thanks for the fix for grouping. It works with the nightly build.

          One more problem I faced when I am trying to set initialSort for a ListGrid on columns with fieldType as Link and Float. For link fieldType, setInitialSort does nothing. For float fieldType, setInitialSort does an alphanumeric sort instead of a numeric sort. Am I doing something wrong, or is this a bug?

          Code:
          DataSourceField field = new DataSourceField("px", FieldType.FLOAT, "Price");
          
          SortSpecifier [] sortspec = new SortSpecifier [1];
          sortspec[0] = new SortSpecifier("px", SortDirection.ASCENDING);
          
          ListGrid.setCanMultiSort(true);
          ListGrid.setInitialSort(sortspec);

          Comment


            #6
            You could create this problem if your actual data values were Strings rather than Numbers.

            Comment


              #7
              Confirming that this works with:
              SmartGWT 3.0p-2012-04-26
              Firefox 6.0.2

              Thanks!

              Comment

              Working...
              X