Disabling selection in CellTable/DataGrid

1,529 views
Skip to first unread message

Mike Dee

unread,
Jun 20, 2012, 3:43:08 PM6/20/12
to google-we...@googlegroups.com
At first I thought this would be easy to do.  But now I'm not sure about what I even want to do.  Maybe I should explain.

I simply want to have a DataGrid and: 1) not have the rows change color when the mouse hovers over them 2) not have the cell selected when I click on one.

At first I thought this could be handled via CSS.  Then I thought that the SelectionModel would handle it.  After some experimenting, I'm not sure which way is up.  In actuality, some DataGrids/CellTables will simply have data and I really want to disable all the hovering and all the cell selection.  In some cases a column will have buttons or checkboxes and I still want to get rid of the hovering and cell selection in these cases too, but if I do, would that disable the buttons and checkboxes?

Mike Dee

unread,
Jun 21, 2012, 4:21:08 PM6/21/12
to google-we...@googlegroups.com
I ended up going with simply changing the CSS. I tried this early without success, but I found out what was going wrong.

The DataGrid CSS can be overridden (as described in many postings here).  In short, custom CSS can be provided to the DataGrid (and CellTable) via the constructor like this.

private DataGrid.Resources tablecss = GWT.create(MyResources.TableCss.class);
@UiField(provided=true) DataGrid<Info> table = new DataGrid<Info>( 10, tablecss );

TableCss is in the ClientBundle and looks like this.

public interface MyResources extends ClientBundle
{
...

// TableCss cell table
public interface TableCss extends DataGrid.Resources
{
@Source({DataGrid.Style.DEFAULT_CSS, "com/mycompany/myapp/client/resources/Table.css"})
DataGridStyle dataGridStyle();
interface DataGridStyle extends DataGrid.Style {}
}

...
}

I've done this before (with CellTable) and it works nicely.  But this time I noticed something that I don't yet understand.  Previously, I've only overridden the CellTable styles that I wanted to change in the CSS file.  In this case, I had to define all the DataGrid styles, that are defined in the default datagrid CSS.  Doing that worked.  Overriding just a few style didn't work, for some reason.

Then I just altered the styles that had to do with hover and keyboard selection.  That gave me the effect I wanted.

Patrick Tucker

unread,
Jun 21, 2012, 5:19:05 PM6/21/12
to google-we...@googlegroups.com
Did you not get what you wanted from the noselectionmodel?

Thomas Broyer

unread,
Jun 22, 2012, 4:39:04 AM6/22/12
to google-we...@googlegroups.com

On Thursday, June 21, 2012 11:19:05 PM UTC+2, Patrick Tucker wrote:
Did you not get what you wanted from the noselectionmodel?

Also, did you try setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED)?

(granted you'd still need to override styling to suppress the "hover" effect)
Reply all
Reply to author
Forward
0 new messages