How to hide column in Cell table GWT?
Asked Answered
D

1

9

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.

Disaffection answered 19/8, 2011 at 3:51 Comment(0)
P
14

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.

Posture answered 22/8, 2011 at 13:41 Comment(1)
How do u manage the Column Ordering issue when insert, remove muptiple columns, pls read this question #21631208Naples

© 2022 - 2024 — McMap. All rights reserved.