Menu

FAQ

q-code

Frequently Asked Questions

How to automate the creation of columns from a dataset?
How to NOT automate the creation of columns from a dataset?
How identifying the columns?
About column order? How changing the column order?
When changing column-definitions, what is the column order?
How to make a column header clickable?
How to remove column?

How to automate the creation of columns from a dataset?

Assuming that $row is an array or a row fetched from a database query:
$t = new cTable(); $t->ChangeTDcontent($row);
This fill the content into the columns, but when column definition is missing, it first creates the column.

How to NOT automate the creation of columns from a dataset?

If you have already defined your columns (for example 3 columns) and you want to populate only these columns with values, without creating extra columns.
Assuming that $row is an array or a row fetched from a database query (containing more that 3 values):
$t = new cTable(); $t->arrTD[0] = new cTableData(); $t->arrTD[1] = new cTableData(); $t->arrTD[3] = new cTableData(); $t->ChangeTDcontent($row,false); // use false option !
This fill the content into the columns and will NOT create extra columns.
Attention: read the FAQ here after on how identifying the columns.

How identifying the columns?

The columns or column-headers are stored in an array ($t->arrTD or $t->arrTH).
When creating column, the array key gives the identification:
$t->arrTH['name'] = new cTableHead('Name'); $t->arrTH['firstname'] = new cTableHead('Firstname'); $t->arrTH['address'] = new cTableHead('Address');
When the key is missing, the key is an integer (starting from 0)
$t->arrTH[] = new cTableHead('Name'); $t->arrTH[] = new cTableHead('Firstname'); $t->arrTH[] = new cTableHead('Address');
In this case, the identifier keys are 0,1,2...
If you mix both:
$t->arrTH['name'] = new cTableHead('Name'); $t->arrTH[] = new cTableHead('Firstname'); $t->arrTH[] = new cTableHead('Address');
The identifiers keys are 'name',0,1,... (the normal behaviour for a php array key)

This is also applicable when automating column definitions from row a dataset
Assuming that $row is an array or a row fetched from a database query:
$t = new cTable(); $t->ChangeTDcontent($row);
Depending on $row, you can have numerical identifiers (when keys are not defined) or the fieldnames (as fieldnames are usually fetched when querying a database)

About column order? How changing the column order?

The column order is simply the creation order. Nevertheless, the columns are stored in an array ($t->arrTH or $t->arrTD) and you can re-order it as you want.

When changing column-definitions, what is the column order?

When changing column-contents (or changing attributes), the changes take into account the column identifiers. Thus, just give identifiers to your new values:
$t->arrTH['A'] = new cTableHead('COLUMN A'); $t->arrTH['B'] = new cTableHead('COLUMN B'); $t->arrTH['C'] = new cTableHead('COLUMN C'); $myColumnNames = array('A'=>'Name','B'=>'Firstname','C'=>'Address'); $t->ChangeTHcontent($myColumnNames);
... Nevertheless, it possible to populate the column-contents in a sequential order (i.e. without respect of the identifiers).
In the following example, we will change the column-content in a sequential order:
$t->arrTH['A'] = new cTableHead('COLUMN A'); $t->arrTH['B'] = new cTableHead('COLUMN B'); $t->arrTH['C'] = new cTableHead('COLUMN C'); $myColumnNames = array('Name','Firstname','Address'); $t->ChangeTHcontent( $myColumnNames, false, false );
Here the last options are false because we don't want to create extra column, and we force using a sequential order. Indeed, in this case, trying to respect the column identifiers would not make any changes (as the identifiers are not matching).

How to make a column header clickable?

A column header can have a link property. It's a pattern where %s will be replaced by the header column name.
Example:
$t->arrTH['A'] = new cTableHead('COLUMN A','','<a href="?order=A">%s</a>');
Here the column name will be included in the ancor.
Note that this link ancor will be used only when required; that's why it is usefull to define your url in the link property rather than directly as the column name. The ancor is used when the table contains several rows and when the column is not active. When the column is active, the link can be absent (or can be different).
Important note: in your link pattern you can use %s only. Do not try to apply php pattern formula (like in printf function).
See the Quick start examples to learn how to handle column orders and switching column order directions.

How to remove column?

Use unset();

Do not remove a column by assigning a null as definition: this may generate inappropriate results when using some advances methods.

Example:
$t->arrTH['A'] = new cTableHead('COLUMN A'); $t->arrTH['B'] = new cTableHead('COLUMN B'); $t->arrTH['C'] = new cTableHead('COLUMN C'); unset( $t->arrTH['B'] );


MongoDB Logo MongoDB