Announcement

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

    ListGrid sort listener

    Hello all,

    Is there any way to add a listener to (or be notified of) a change in sorting in a listgrid? I need to execute some logic when the sorting of any column in a list grid has changed. Is this possible?

    thanks

    #2
    I need to do the same thing. Anyone have an idea how to accomplish this? I figured I might put a click handler on the column headers, but I don't know how to access them as yet.

    Comment


      #3
      Hi,

      The ListGrid header clicks are not yet handled in SmartGWT.

      Here is the thread related to the issue:
      http://forums.smartclient.com/showthread.php?t=3055

      And the bug report on SmartGWT's google code page:
      http://code.google.com/p/smartgwt/is...ary%20Reporter

      If you find a work around, I'm interested...

      Also, I've been experiencing some issues when calling ListGrid.getSortDirection().
      http://forums.smartclient.com/showthread.php?t=4409
      Thought you might have come accross the same problem.
      Last edited by dn; 10 Mar 2009, 10:05.

      Comment


        #4
        We're looking into exposing this in SmartGWT, and the issue when calling ListGrid.getSortDirection()

        Comment


          #5
          workaround

          add a ClickHandler and look for the event row equal to -1

          -1 means the header...

          Code:
          new ClickHandler() {
             public void onClick(ClickEvent event) {  
                int eventColumn = ((ListGrid)event.getSource()).getEventColumn();
                int eventRow = ((ListGrid)event.getSource()).getEventRow();
                if (eventRow == -1) {
                   SC.say("Event Column: "+eventColumn + " - Event Row: " + eventRow);
                }
             }
          }
          im still new to SmartGWT so im hoping that was correct...

          Comment


            #6
            Hi rasgallego,

            Good idea!
            Unfortunately, that doesn't help stopping a column from being sorted (and replacing that by a custom action).

            Comment


              #7
              Hi dn,

              Yeah, unfortunately it won't.
              But for tracking if a user sorted the grid then its ok for now.

              I just recently found out that there is also a problem with that workaround.
              When the user clicks on the submenu in the column, the event also gets triggered.

              Comment


                #8
                You can add a clickHandler at the level of the MenuItem

                Hi,

                I also need to change the functionality of sorting. What i did is to override the ListGrid's getHeaderContextMenuItems(final Integer fieldNum) method. In it, I check the MenuItems that correspond to the Sort Ascending and Sort Descending. For those, i added a ClickHandler. In my click handler, i implement my own sorting functionality.
                I don't know if that might be helpful to you.


                However, my problem is that since my clickhandler does not change the sorting that takes place when the header is clicked, what happens is:
                If i click on column B's header, the client-side sorting takes place.
                Then if i choose column A's modified "Sort Descending" menu item, the server side sorting that i implemented is done, but the records retrieved are re-sorted in the grid by column B's field and direction and the sorting arrow is still showing on Column B, not column A.

                The grid's new sort field and sort direction is not being set to the new values, although i tried adding all the following lines, but nothing worked:

                Code:
                 
                ListGridWithButtonsCol.this.unsort();
                ListGridWithButtonsCol.this.setSortField(fieldNum);
                ListGridWithButtonsCol.this.setSortDirection(SortDirection.DESCENDING);
                ListGridWithButtonsCol.this.setShowSortArrow(SortArrow.NONE);
                ListGridWithButtonsCol.this.refreshRow(0);
                ListGridWithButtonsCol.this.adjustForContent(true);
                ListGridWithButtonsCol.this.headerClick(fieldNum);
                Any idea why and how i can fix this?
                Any help is greatly appreciated.
                Thanks.

                Comment


                  #9
                  There is a designed-in way to customize sorting - setting a SortNormalizer. Unless you have very unusual requirements, this is the right approach and you should abandon your attempts to customize the menu.

                  Comment


                    #10
                    Hi,

                    Thanks for your reply.

                    I tried it. But, this normalizer is called for every record in the grid. So, if i implement in it my RPC call to the server's sort method, it will be called 10 times for a 10-sized page, 20 times for a 20-sized page, etc.
                    So, this wouldn't be efficient at all.

                    Please let me know if there's another solution or if I've misunderstood anything about this suggested solution.

                    Thanks in advance,
                    Nicole.

                    Comment


                      #11
                      Hi Nicole,

                      All sort algorithms visit every item in the dataset, so this is normal and efficient, and this is how all the built-in sort routines work.

                      Comment


                        #12
                        There is a designed-in way to customize sorting - setting a SortNormalizer. Unless you have very unusual requirements, this is the right approach ...
                        Here is a potentially unusual approach that doesn't seem achievable without handling the header click:

                        Given an initial set of N records (can be a big number), a subset of P < N records is shown on the ListGrid.
                        On a header click, the sort is applied to the whole set of N records and the ListGrid updated accordingly, showing again a subset of P records.

                        Any updates on the bugfix? :-)

                        Thanks,

                        Dogan

                        Comment


                          #13
                          @dn we are adding a handler for this, but your proposed use case seems pretty much unrelated?

                          Comment


                            #14
                            Hi again,

                            Isomorphic, the thing is that i wouldn't want to visit the sorting for every record, since i am doing the sorting on the server side. In fact, the scenario mentioned by dn is exactly what i am doing. When sorting is chosen, i have an RPC call to the server, where the sorting on the full set of records is done, and P sorted records are returned. Since they're already sorted, i don't want the sortnormalizer to resort anything.

                            I also just want to override the HeaderClick as dn mentioned. I tried it, but my overridden method never gets called. Is that a bug?

                            Thanks.
                            Last edited by nicole.baz; 24 Apr 2009, 00:32.

                            Comment


                              #15
                              Hi Nicole,

                              You seem like you may be re-inventing the wheel. When you use databinding your grid has a ResultSet that automatically switches between client and server-side sorting as necessary. See the ResultSet docs.

                              Comment

                              Working...
                              X