I made a dynamic CellTable using this question as guide : Create GWT CellTable Dynamically
But like that I can only made a editable CellTable, I don't know why.
Check my Code:
@UiField
CellTable<List<String>> tableDynamic;
@UiField
SimplePager pagerDynamic;
private SingleSelectionModel<List<String>>
selectionModelDynamic = new SingleSelectionModel<List<String>>();
private List<String> columns = new ArrayList<String>();
private List<List<String>> data = new ArrayList<List<String>>();
private ListDataProvider<List<String>> providerDynamic
= new ListDataProvider<List<String>>();
My Factory
@UiFactory
public CellTable<List<String>> getTabelaDynamic() {
CellTable<List<String>> table
= new com.google.gwt.user.cellview.client.CellTable<List<String>>();
//List<String> columnsArray = colunas;
List<String> columnsArray = columns();
for (int column = 0; column < columnsArray.size(); column++) {
table.addColumn(new IndexedColumn(column), new
TextHeader(columnsArray.get(column)));
}
table.setKeyboardSelectionPolicy
(HasKeyboardSelectionPolicy.KeyboardSelectionPolicy.ENABLED);
table.setSelectionModel(selectionModelDynamic);
providerDynamic.addDataDisplay(table);
providerDynamic.setList(new ArrayList<List<String>>());
return table;
}
Method to get Columns:
//Just a static test
public List<String> columns(){
colunas.add("Tables");
return colunas;
}
Method for setting data with only one column.
@Override
public void setSingleData(List<String> bankData) {
for (String s : bankData) {
List<String> help = new ArrayList<String>();
help.add(s);
dados.add(help);
}
providerDynamic.setList(data);
}
I Do a rpc call(onBind method) to get the list and populate on setsingledata method.
Why I'm receiving a editable celltable?
Your table is editable because IndexedColumn uses EditTextCell in the other question. Use TextCell and your table will not be editable.