wonu wns
wonu wns

Reputation: 3608

Allow scrolling and sorting to GWT Grid

Good day. I'm making a application with tables using GWT Grid. Now, I want my GWT Grid to have a scrollbar when rowCount is greater than 15. The header is not part of the scrollable area.

My problems are:

  1. How can I enable table/grid content scrolling without including the header?
  2. How can I make my table header look like a button wherein users can click it to sort the specific column?

My current code will allow scrolling when rowCount > 15 including the header. Please help. Thanks in advance.

Upvotes: 3

Views: 7183

Answers (2)

Thomas Broyer
Thomas Broyer

Reputation: 64541

Maybe it's time to switch to cell widgets, and DataGrid.

  1. Javadoc
  2. Live example (with code)
  3. Documentation on cell widgets, and how to do column sorting (a DataGrid is almost like a CellTable).

Upvotes: 6

Raidok
Raidok

Reputation: 764

Scrolling

I won't dig deep into GWT with this post but I'll try to give some hints on how to do the scrolling part.

If your table's data is wrapped in a separate tag than the table's body, then it shouldn't be a problem. If the table's structure is similar to the following, it shouldn't be a problem:

<table>
    <thead>
        <tr>
            <th>ColumnHeader1</th>
            <th>ColumnHeader2</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <th>Data1</th>
            <th>Data2</th>
        </tr>
    </tbody>
</table>

To make the data part vertically scrollable, you should add a CSS style to the <tbody> element which sets overflow-y: scroll; when the rowcount is greater than 15. Also you need to set the height or limit it's height by other means (wrapping container) for the scrollbar to appear.

To set the height, I'd consider to get the <tbody>'s offset height right after the 15th row has been added and force it to stay at that. It might go like this:

tbodyElement.setHeight(tbodyElement.getOffsetHeight());

Remember, this has to be done right after adding the 15th row.

Sorting

For that you should wrap your column header names in some kind of a Widget. It could be a HTML or a Label for example. You just need to add ClickHandlers to them and some styling to fill the whole cell and the cursor to switch to a hand with CSS cursor: pointer; while hovering on it.

Conclusion

Well, this was my light overview of this. Without seeing the code you've done it's hard to go any further.

Upvotes: 0

Related Questions