tags:

views:

342

answers:

1

I have a column Definition for each colume that extends AbstractColumnDefinition these columns are put in a DefaultTableDefinition PART OF a PagingScrollTable

example:

NAME | SIZE | RES | DELETE |

this style (AT THE END OF THE PAGE ) is added to the column names if you notice all of them are with a cursor pointer , meaning a hand shows up when i hover above each one. I want to remove the cursor for some cells in the header like delete.

HOW DO YOU set/add/remove a style on a particular cell of the header table of a PagingScrollTable?

THANK YOU

.gwt-ScrollTable .headerTable td {

border-left: 1px solid #CCCCCC;

border-right: 1px solid #CCCCCC;

border-bottom: 1px solid black;

vertical-align: bottom;

cursor: pointer;

}

A: 

Edit 2 updated this again because the OP's question is finally clear: how do you set a style on a particular cell of the header table of a PagingScrollTable?

PagingScrollTable scrollTable = ...
scrollTable.getHeaderTable().getCellFormatter().addStyleName(row, column, "myStyleName");

where row and column are 0-based integers indicating which cell of the header table to set the style on.

Edit updated this to explain how to set a style on the header, since the person asking the question clarified that's what they want.

If you want to add a style to the header of a PagingScrollTable, just do this:

PagingScrollTable scrollTable = ...
scrollTable.getHeaderTable().addStyleName(row, "myStyleName");

and then put in a CSS rule for myStyleName to set the cursor to whichever one you want, like so:

.myStyleName {
  cursor: default;
}

Note that the reason why the cursor is a pointer is that clicking on a column header in a PagingScrollTable will sort the table by that column. To disable that, call scrollTable.setSortPolicy(AbstractScrollTable.SortPolicy.DISABLED

Original answer This will add a style to a column in the body of the table, but not the header or footer:

Since you mention ColumnDefinition I presume you're talking about PagingScrollTable. In that case, the way to add a CSS style to a cell is in the CellRenderer for the cell. Once you've got a ColumnDefinition, do something like this:

CellRenderer<YourRowType, String> cellRenderer = new CellRenderer<YourRowType, String>() {
  public void renderRowValue(RowType rowValue, ColumnDefinition<RowType, String> columnDef,
                             TableDefinition.AbstractCellView<RowType> view) {
    view.setHTML(value);
    view.addStyleName("myStyleName");
  }
};

columnDefinition.setCellRenderer(cellRenderer);

You'll have to change the type parameters of CellRenderer<YourRowType, String> appropriately, but that's more or less how to do it.

aem
Thank you for your time and help , I might not have said clearly which part of the table I want to add the style , I would like to change or add style to the header name .. deleteDef.setHeader(0, "Delete"); so it would NOT show the hand cursor !!! deleteDef extends AbstractColumnDefinition in a DefaultTableDefinition and yes I'm using PagingScrollTable ... So just would like to remove the headers style . NB: your code worked on the hole column instead of the header.
Mario
Great Example and code , but this function removes the cursor for all of the tableheader.. in my table header .. I have "name" , "size" , "delete" and "resolution" , I only want to remove the cursor for the delete column , if that is possible !! because Im starting to think it is NOT !! :D thank you so much for your help !!
Mario
Hello, So I tried the last function you gave me but it didn’t work.. Something weird is going on!!So when I do: pageTable.getHeaderTable().removeStyleName("headerTable");it does remove the css style for the head .. so I think we are on the right track.Second when I go in to change or add style. pageTable.getHeaderTable().getCellFormatter().addStyleName(0, 2, "cursor-remove");
Mario
0 meaning the top row 2 meaning the third column which represents a cell and remove the cursor , it remains , i tried placing this function lots of places in the code and it didn’t work , also tried with getRow and getColumn formatters and still same result !! I also tried to place the style in diff. css files ... and also tried added diff css styles to see if it changes anything , I checked it in firebug but the css code that I try to add or set is just not showing up .
Mario
NOTE: I also noticed when I try to removestyle on a cell of any kind it gives me a IndexOutOfBoundsException ( Row index: 0, Row size: 0) ;when i try to add or set it doesn’t ... which is pretty weirdpageTable.getHeaderTable().getCellFormatter().removeStyleName(2, 2, "headerTable");
Mario
pageTable.getHeaderTable().getCellFormatter().setStylePrimaryName(0, 1, "cursor-remove"); this also gives an error ..(TypeError): 'rows[...].cells' is null or not an object number: -2146823281 description: 'rows[...].cells' is null or not an object
Mario