How to hide column in Cell table GWT?

青春壹個敷衍的年華 提交于 2020-01-01 08:47:15

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/7116758/how-to-hide-column-in-cell-table-gwt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!