How to hide column in Cell table GWT?

Sanjay Jain picture Sanjay Jain · Aug 19, 2011 · Viewed 8.9k times · Source

I am using Cell Table in GWT.In that cell table I am adding these columns.

    TextColumn<Document> idColumn = new TextColumn<Document>() {
        @Override
        public String getValue(Document object) {
            return Long.toString(object.getId());
        }
    };
    TextColumn<Document> refColumn = new TextColumn<Document>() {
        @Override
        public String getValue(Document object) {
            return object.getReferenceNumber();
        }
    };
    /*
     * DateCell dateCell = new DateCell(); Column<Contact, Date> dateColumn
     * = new Column<Contact, Date>(dateCell) {
     * 
     * @Override public Date getValue(Contact object) { return
     * object.birthday; } };
     */
    TextColumn<Document> nameColumn = new TextColumn<Document>() {
        @Override
        public String getValue(Document object) {
            return object.getDocumentName();
        }
    };
            table = new CellTable<T>();
    table.addColumn(idColumn, "Id");
    table.addColumn(refColumn, "Reference Number");
    table.addColumn(nameColumn, "Name");
}

Now I have some queries: How to hide the id column? On click of row how can i get the from selected row? Please help me out. Thanks in advance.

Answer

&#220;mit picture Ümit · Aug 22, 2011

Well you could try to use fixed layout for the CellTable and set the width of the specific column you want to hide to 0px. I did use another approach.

In my case I have a cellTable which should display a checkbox column as soon as I press a button (which puts the celltable in edit mode). I do this by creating a CheckBoxColumn and inserting and removing it when I press on the button. It looks seomething like that:

@Override
public void insertCheckBoxColumn(Column<Object,Boolean> column) {
    if (cellTable.getColumnIndex(column) == -1) {
        cellTable.addColumn(column,"");
        cellTable.setColumnWidth(column,50, Unit.PX);
    }
}

@Override
public void removeCheckBoxColumn(Column<Object, Boolean> column) {
    int index = cellTable.getColumnIndex(column);
    if (index != -1)
         cellTable.removeColumn(index);
}

However note that you might run into this issue on google chrome.