Announcement

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

    ListGridField.setSortDirection() not working?

    I'm using SmartGWT 2.4 trying to set the initial sort direction for a particular column in a list grid.

    The javadoc for the setSortDirection() method in ListGridField says:

    Specifies the default sorting direction for this column. If specified on the sortField for the listGrid, sorting occurs automatically, otherwise this will be the default direction when the user clicks the field header, or calls ListGrid.sort() without specifying an explicit sort direction.

    That is exactly what I want - I have a numeric column that I would like to sort descending when the user clicks on the header for the first time. But calling that method for that field doesn't seem to have any effect - the column is still sorted in ascending order when I click on it.

    Here is my simple test program that illustrates this problem:

    Code:
        private static final String SALARY = "Salary";
        private static final String JOB = "Job";
        private static final String NAME = "Name";
    
        public void onModuleLoad()
        {
            final ListGrid listGrid = new ListGrid();  
            listGrid.setWidth(500);  
            listGrid.setHeight(400);  
      
            ListGridField nameField = new ListGridField(NAME, 150);  
            ListGridField jobField = new ListGridField(JOB, 150);  
            ListGridField salaryField = new ListGridField(SALARY);
            salaryField.setType(ListGridFieldType.INTEGER);
            salaryField.setSortDirection(SortDirection.DESCENDING);
      
            listGrid.setFields(nameField, jobField, salaryField);  
      
            listGrid.setData(getData());
            
            listGrid.draw();  
        }
    
        private ListGridRecord[] getData()
        {
            ListGridRecord[] records = new ListGridRecord[] {
                    makeRecord("Charles Madigen", "CEO", 26200),
                    makeRecord("Joan Little", "Mgr", 19600),
                    makeRecord("Kirel Amirov", "Tech Mgr", 19500),
                    makeRecord("Tammy Plant", "Secretary", 18800),
                    makeRecord("Glenda Witch", "Worker", 15000),
                    makeRecord("Pat Freel", "Clerk", 12000),
                    makeRecord("Brenda Cox", "Owner", 45000)
            };
            
            return records;
        }
    
        private ListGridRecord makeRecord(String name, String job, int salary)
        {
            ListGridRecord record = new ListGridRecord();
            
            record.setAttribute(NAME, name);
            record.setAttribute(JOB, job);
            record.setAttribute(SALARY, salary);
    
            return record;
        }
    I have looked over the ShowCase Grid Sort example at http://www.smartclient.com/smartgwt/showcase/#grid_sort_sort

    It seems to work in that example - I don't why it works there but not in my sample application.

    This thread http://forums.smartclient.com/showthread.php?t=12493&highlight=setSortDirection describes the same problem - but the workaround "fix" described there doesn't even compile for me.

    #2
    Any hints or suggestions?

    Comment


      #3
      I'm having the exact same problem, same SmartGWT version. Can anybody from Isomorphic or elsewhere help with this?

      Thanks

      Comment


        #4
        I think this qualifies as a bug, given the simple and reproducible nature of this problem. Is there an official mechanism for logging a bug?

        Thanks

        Comment


          #5
          Is the setSortField(fieldName) working?
          It doesn't seem to work either.

          Thanks.
          Last edited by curiousgally; 7 Apr 2011, 07:19.

          Comment


            #6
            Hey!

            I had the same problem... may solution:
            I made an hidden field called "idx" with an continuously number... not the best solution, but in my case it works:

            ListGrid:
            table.setSortDirection(SortDirection.DESCENDING);
            table.setSortField("idx");

            Record:
            record.setAttribute("idx", idx++);

            Comment

            Working...
            X