Tables
The Table object displays string data. Any formating must be done before values are put into a Table.
Example code:
final List<String> columns = List.of("Person", "Hobby", "Age");
final Table table = new Table("Hobbies", columns);
table.append(Map.of("Person", "Pierre", "Hobby", "Pétanque", "Age", "42"));
table.append(Map.of("Person", "Paul", "Hobby", "Rugby", "Age", "35"));
table.append(Map.of("Person", "Jacques", "Hobby", "Cycling", "Age", "50"));
produces:
Person | Hobby | Age |
---|---|---|
Pierre | Pétanque | 42 |
Paul | Rugby | 35 |
Jacques | Cycling | 50 |
Display options
table.hideHead();
Person | Hobby | Age |
---|---|---|
Pierre | Pétanque | 42 |
Paul | Rugby | 35 |
Jacques | Cycling | 50 |
table.hideColumn("Age");
Person | Hobby | Age |
---|---|---|
Pierre | Pétanque | 42 |
Paul | Rugby | 35 |
Jacques | Cycling | 50 |
table.hideTitle();
Person | Hobby | Age |
---|---|---|
Pierre | Pétanque | 42 |
Paul | Rugby | 35 |
Jacques | Cycling | 50 |
Pagination
When the table is too long to be displayed at once, then you can configure a pagination. Of course it is not available on
a static Table, you will need the Table to have a source and a corresponding web service on backend side.
int pageSize = 12;
table.setPaging(pageSize);
Once you have set a paging size on your table, it will be displayed with page information and navigation buttons.
The page your are reading is static, that's why it is not possible to show any example of pagination, sorry.
At the backend side, you must provider a TableData object which contains the rows of the selected page, and the pagination information. There is a convenient way to obtain a TableData instance from either a Table, a TablePicker or a TableData, this is the method getPage:
// Getting or building the table
Table table = [...]
// Reading page number and page size from request
int pageNumber = reader.getIntParameter(Table.PARAMETER_PAGE_NUMBER);
int pageSize = reader.getIntParameter(Table.PARAMETER_PAGE_SIZE);
// Giving back the TableData of selected page
TableData dataToRespond = table.getPage(pageNumber, pageSize, table.size());