Sorting a CellTable server-side

后端 未结 4 1134
说谎
说谎 2021-01-24 14:30

I\'m currently using a Gwt CellTable, bound to my GAE/Objectify backend via RPC calls.

All right now! :-)

Then I want to sort columns, so I read http://code.goog

4条回答
  •  醉话见心
    2021-01-24 14:39

    A bit late to the party, but here's a more straight-forward solution based off of the current documentation (see section 'ColumnSorting with AsyncDataProvider').

    When we're adding our columns we can simply set the dataStoreName:

    TextColumn surname = new TextColumn() {
        ...
    }
    surname.setSortable(true);
    surname.setDataStoreName("surname");  // Set the column name
    table.getColumnSortList().push(surname);
    table.addColumn(surname, "Last Name");  // eg. A different name for the UI
    

    Then we can retrieve the column's dataStoreName later when sorting:

    @Override
    protected void onRangedChanged(HasData display) {
        ...
        ColumnSortList.ColumnSortInfo info = table.getColumnSortList().get(0);
        String sortColumn = info.getColumn().getDataStoreName();  // Get the column name
        boolean sortIsAscending = info.isAscending();
    
        rpcService.requestMyData(
            sortColumn,
            sortIsAscending,
            new AsyncCallback>() {...}
        );
        ...
    }
    

    Using this method we can pass the column name directly to our RPC method. It even allows us to use a different name (eg. the database column name) than the column name used on the UI/client side.

提交回复
热议问题