Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Scout » Table with dynamic number of columns
Table with dynamic number of columns [message #889307] Tue, 19 June 2012 05:34 Go to next message
Patrick Baenziger is currently offline Patrick BaenzigerFriend
Messages: 96
Registered: September 2011
Hello everyone

In my application, I need to create a form describing a set of „changes". Usually those are describe in a „Name-Value" like style.
Until now, I used a table with a single column (String column with HTML) to describe the changes, using multiline-cells. Something like this:

Event name: Birthday party
Location: Grand Central Park
Duration: 180 minutes

Event name: Funeral
Location: Grand Central Cemetery
Duration: 60 minutes

Now the question came up whether we could transform this into a horizontal form (i.e. a table with more than one column).

While one set of changes would have the same number of columns, another set may have a larger (or smaller) number of columns.
Until now, I just had a fixed number of columns or made as many columns as one might need (and just hide the ones that are not necessary).

But in general (or for an unknown number of columns, is it possible in Scout to tell a table at runtime to create N columns which we can then fill?

Re: Table with dynamic number of columns [message #889338 is a reply to message #889307] Tue, 19 June 2012 06:19 Go to previous messageGo to next message
Adrian MoserFriend
Messages: 67
Registered: March 2011
Have a look at AbstractTableCustomizer.
If you override injectCustomColumns(), you can add columns to the list at runtime.

You need to add your TableCustomizer to your table by overriding
public ITableCustomizer getTableCustomizer()

Hope that helps

[Updated on: Tue, 19 June 2012 06:23]

Report message to a moderator

Re: Table with dynamic number of columns [message #889381 is a reply to message #889307] Tue, 19 June 2012 07:19 Go to previous messageGo to next message
Ivan Motsch is currently offline Ivan MotschFriend
Messages: 154
Registered: March 2010
Senior Member
This is an example:

import java.util.ArrayList;
import java.util.List;

import org.eclipse.scout.commons.annotations.Order;
import org.eclipse.scout.commons.exception.ProcessingException;
import org.eclipse.scout.rt.client.ui.basic.cell.Cell;
import org.eclipse.scout.rt.client.ui.basic.table.AbstractTable;
import org.eclipse.scout.rt.client.ui.basic.table.HeaderCell;
import org.eclipse.scout.rt.client.ui.basic.table.ITableRow;
import org.eclipse.scout.rt.client.ui.basic.table.columns.AbstractColumn;
import org.eclipse.scout.rt.client.ui.basic.table.columns.AbstractDoubleColumn;
import org.eclipse.scout.rt.client.ui.basic.table.columns.AbstractLongColumn;
import org.eclipse.scout.rt.client.ui.basic.table.columns.IColumn;
import org.eclipse.scout.rt.client.ui.desktop.outline.pages.AbstractPageWithTable;
import org.eclipse.scout.rt.client.ui.desktop.outline.pages.ISearchForm;
import org.eclipse.scout.rt.shared.TEXTS;
import org.eclipse.scout.service.SERVICES;

public class DynamicColumnsTablePage extends AbstractPageWithTable<DynamicColumnsTablePage.Table> {
  private List<IColumn<?>> m_injectedColumns;

  protected String getConfiguredIconId() {
    return Icons.TreeNode;

  protected boolean getConfiguredLeaf() {
    return true;

  protected Class<? extends ISearchForm> getConfiguredSearchForm() {
    return DynamicDataSearchForm.class;

  protected boolean getConfiguredSearchRequired() {
    return true;

  protected String getConfiguredTitle() {
    return TEXTS.get("DynamicColumns");

  protected Object[][] execLoadTableData(SearchFilter filter) throws ProcessingException {
    DynamicDataSearchFormData formData = (DynamicDataSearchFormData) filter.getFormData();
    DynamicDataMatrixData matrixData = SERVICES.getService(IDynamicDataPageService.class).getStatisticsMatrixData(formData);
    if (matrixData == null) {
      return new Object[0][];
    //create dynamic columns based on matrix data assuming matrixData has a property "getColumnSpecs" with  bean ColumnSpec
    //fill rows
    return matrixData.getRows();
  private void updateDynamicColumns(ColumnSpec[] columnSpecs) throws ProcessingException {
    if (columnSpecs.length == 0) {
    Table table = getTable();
    m_injectedColumns = new ArrayList<IColumn<?>>();
    for (ColumnSpec spec: columnSpecs) {
      //XXX switch on spec.getType() or something like that...
      m_injectedColumns.add(createDynamicDoubleColumn(spec.getId(), spec.getText()));

  private IColumn<?> createDynamicDoubleColumn(final String columnId, final String label) {
    return new AbstractDoubleColumn() {
      protected String getConfiguredHeaderText() {
        return label;

      public String getColumnId() {
        return columnId;

      protected int getConfiguredWidth() {
        return 120;

      protected Double execParseValue(ITableRow row, Object rawValue) throws ProcessingException {
        rawValue = preprocessDynamicColumnsCell(this, row, rawValue);
        return super.execParseValue(row, rawValue);

   * @return {@link DecoratedValue#getValue()} after decorating the table cell
  private Object preprocessDynamicColumnsCell(IColumn<?> col, ITableRow row, Object rawValue) throws ProcessingException {
    DecoratedValue rawCell = (DecoratedValue) rawValue;
    if (rawCell != null) {
      return rawCell.getValue();
    return rawValue;

  public class Table extends AbstractTable {

    protected boolean getConfiguredSortEnabled() {
      return false;

    protected void injectColumnsInternal(List<IColumn<?>> columnList) {
      if (m_injectedColumns != null) {

icon14.gif  Re: Table with dynamic number of columns [message #889480 is a reply to message #889307] Tue, 19 June 2012 09:19 Go to previous messageGo to next message
Patrick Baenziger is currently offline Patrick BaenzigerFriend
Messages: 96
Registered: September 2011
Great, thank you both for your speedy replies!
Re: Table with dynamic number of columns [message #1726861 is a reply to message #889381] Thu, 17 March 2016 06:26 Go to previous messageGo to next message
Vijayachandra kumar ramamurthy is currently offline Vijayachandra kumar ramamurthyFriend
Messages: 7
Registered: December 2015
Junior Member
Hi Ivan,

Great Example...

It would be great if complete source of this example is posted?, please. Also please share class definitions for DynamicDataMatrixData, Columnspec, DecoratedValue, and its IDynamicDataPageService.

Thanks in advance.

Re: Table with dynamic number of columns [message #1862403 is a reply to message #1726861] Fri, 01 December 2023 16:05 Go to previous message
Oueslati Anis is currently offline Oueslati AnisFriend
Messages: 128
Registered: June 2014
Location: Paris
Senior Member
This is very interesting could you please share the complete code exemple with us
Previous Topic:Refresh a listbox with a LookupCall backend
Next Topic:Concurrent access to Scout application
Goto Forum:

Current Time: Mon Mar 04 02:01:52 GMT 2024

Powered by FUDForum. Page generated in 0.02557 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top