Problem

How can I use the table component of a form unbound to datasource.


Solution

You can use the table component of a form, by adding rows and columns and setting the cell type (Label, Testbox, CecheBox, Button).
Suppose you want to load a grid of 3 columns the first of type Label, the second of type TextBox and the third of type CheckBox , so:

dataweb.client.components.table.TableColumn tc =null;

//Create the first column of type Label (the default)
tc = tableComponent.addColumn();

//Create the second column of type Textbox
tc = tableComponent.addColumn();
tc.getDefaultCell().setType(dataweb.client.components.TextBox.class);

//Create the third column of type CheckBox
tc = tableComponent.addColumn();
tc.getDefaultCell().setType(dataweb.client.components.CheckBox.class);

//Now we load the rows and set the cell values:
dataweb.client.components.table.TableRow tr =null;
nrows=10;
for (int i=0;i<=nrows-1;i++){
tr = tableComponent.addRow();
   tableComponent.getCell(tr.getIndex(), 0).setValue("lbl r:" + tr.getIndex() + " c:" + 2);
   tableComponent.getCell(tr.getIndex(), 1).setValue("txt r:" + tr.getIndex() + " c:" + 2);
   tableComponent.getCell(tr.getIndex(), 2).setValue(true);
}

If we want the cell index (3,1) is of type Button:

dataweb.client.components.table.Cell cell = tableComponent.getCell(1,1);
cell.setType(dataweb.client.components.Button.class);
cell.setValue("test btn");

Other useful methods are:

getRowCount(); //Indicates the number of rows
getColumnCount(); //Indicates the number of columns
setRowFixedCount(nr); //Still makes the first <nr> rows
setColumnFixedCount(nc); //Still makes the first <nc> columns
clear(); //Removes all cells
clearRows(); //Removes all rows
clearNoFixedRows(); //Remove all rows except those fixed

Published in Wed, 29 December 2010 18:42