Filosssof
Filosssof

Reputation: 1358

How to add dynamically a column to grid GXT?

I want to add new column on grid GXT, and I done this, but when I try to sort grid by this column all data is erased and appears:

IllegalArgumentException: property can not be null or empty

After this I tried to set data index xxx to column config and in this case I got another exception:

Cannot find in grid store property with this name

This is my code for dynamically adding new column:

@Override
    public List<ColumnConfig> getTableColumns() {
        List<ColumnConfig> tableColumns = super.getTableColumns();
        ColumnConfig downloadLink = new ColumnConfig();
        downloadLink.setRenderer(new GridCellRenderer() {
            @Override
            public Object render(ModelData modelData, String s, ColumnData columnData, int i, int i1, ListStore listStore, Grid grid) {
                if (modelData.get("uuid")!=null) {
                    Anchor anchor = new Anchor();
                    anchor.setHref(GWT.getModuleBaseURL() + "download?uuid=" + modelData.get("uuid"));
                    anchor.setName("name");
                    anchor.setText("Download");
                    return anchor;
                }else{
                    return "N/A";
                }
            }
        });
        downloadLink.setWidth(100);
        downloadLink.setHeader("Download");
//        downloadLink.setDataIndex("downloadLink");
        tableColumns.add(downloadLink);
        return tableColumns;
    }

How can I make new column to be sortable?

Upvotes: 1

Views: 456

Answers (1)

Brandon
Brandon

Reputation: 2084

grid.reconfigure can be used to change the columns.

final ColumnModel<Stock> cm2 = new ColumnModel<Stock>(columns);
grid.reconfigure(store, cm2);

Upvotes: 1

Related Questions