Announcement

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

    Sorting on one table depending on sorting on another table...possible?

    Hello everybody
    I need some help for a feature i'm not sure is available in smartGWT. I'm using the last version.
    I have 2 tables displayed on the same page with a divider in the middle.
    They have the same id but different fields.
    When I click on a column on the first table, I wanna reflect the sorting on the second table (they need to be joined based on the primary key to do that)
    I first tried creating one datasource for both tables (easier for the sorting) displaying only the right fields in each table (hidden true / false) but this won't work as both tables have to be displayed on the same page - fields get either all showed or all hidden as each table holds a reference to the same datasource...

    So I tried another approach: I created 2 different datasources with the same primary key.
    I declared the second datasource as "inheritsFrom" the first datasource (so that in the second datasource also the fields from the first datasource are available) and showLocalFieldsOnly="true".
    They do get displayed correctly. Now for the sorting I put a headerClickHandler on the columns of the first table, and looks like this:

    firstTable.addHeaderClickHandler(new HeaderClickHandler() {
    @Override
    public void onHeaderClick(HeaderClickEvent event) {
    secondTable.setSort(firstTable.getSort());
    }
    });


    Now, this thing has a very strange behaviour.
    The sorting on the second table happens quite randomly.
    Or better: if I click on the header of the primaryKey of the first table, they both get sorted.
    If afterwards I click on the header on another column of the first table, the second gets sorted. OK.
    But from then on, whatever header I click in the first table, the column on the first table gets sorted but the sorting isn't "propagated" to the second table. Nothing happens there.
    When I debug I see it ALWAYS enters the onHeaderClick method and it executed the instruction
    secondTable.setSort(firstTable.getSort());
    with no exeptions, but nothing happens.
    I tried this instead
    ListGridField clickedColumn = firstTable.getField(event.getFieldNum());
    secondTable.sort(clickedColumn.getName(), clickedColumn.getSortDirection());

    because this sort method is returning a boolean which says if the sorting has happened or not.
    In this case actually "null" is returned. Why?

    Should I find a solution to this specific problem, or am I taking the wrong approach here?
    In this case what's the best solution to make a table sort depending on another table?
    Is there any way in smart gwt to sort a table passing a list of values in the right order for a specific column (for me would be the primary key)?
    Thanks a lot for any suggestions, I'm kind of out of ideas here.
    Cheers


    Laura

    #2
    Not clear why your trying to do this (why just use one grid?) but if you want two ListGrids to share a dataset, hand-create a ResultSet and provide it to both grids.

    Comment


      #3
      Thanks a lot for your reply. We found another way to do this.
      Laura

      Comment

      Working...
      X