The following is a quick overview of each column type you can add to a Table.
- CallableColumn: this is the most versatile of the column types, and lets you
specify a callback which returns the text of each cell in the column. The callback must be a valid PHP
callable callback function.
The one caveat is that you cannot use PHP Closures here,
because QCubed needs to serialize everything in the form to preserve its state, and closures cannot
- PropertyColumn: this is useful when the data source is an array of objects,
and cell data can be fetched by simply calling a property on each item. A property can be a member
variable, or a property returned by the __get PHP magic method. Properites can be chained.
- IndexedColumn: this is useful when the DataSource is an array of arrays.
You can specify which item in the array should be drawn in the column. You can also specify data
that is multiple levels deep into the array.
- NodeColumn: If the DataSource is an array of database objects, like the array
returned by the queryArray() method, you can
specify what data should be displayed using a QCubed Node object. For example, to display the first name of
a person, you would enter QQN::person()->FirstName. Nodes are chainable.
- VirtualAttributeColumn: If the DataSource is an array of database objects, and those
objects also have VirtualAttributes in them, a VirtualAttributeColumn lets
you easily display the value of the attribute.
- CheckboxColumn: This column lets you display a column of checkboxes that the
user can select, and then query later. Checkbox columns can be complex, and is described more fully in
- LinkColumn: This column lets you display an html link (anchor tag), or a button, whose
contents are dependent on the values in the DataSource row. Link columns can have many options for how to
set them up, and are described more in a different example.
Each of these columns can be created and then added to the table, and most can also be created and added in
one step using the following shortcuts in the Table class:
datagrid controls such as the jqGrid and DataTables jQuery
The first example demonstrates how to use property and callable based columns when the DataSource is an array of objects.
The first column is using a Callable, to
compute the value of the cells.
The second column uses the "LastName" property to get the value of the cells.
The second example demonstrates how to use the indexed columns when the DataSource is an array of arrays. This is
typically necessary in complex reports, when the data comes from external sources or cannot be easily generated with
a simple QQuery.
The first 4 columns will use an indexed access to the DataSource arrays.
The last column will use "#count" as the key into the array.
Of course in a real world case, these two types of columns will not be mixed - one would either use a simple
indexed array, or a fully associative array.
This example demonstrates how to override a column to create a complex header. Table\ColumnBase and its subclasses have
a variety of hooks to return ids, classes and other attributes for whole rows, columns or individual cells.
This example creates a colspan for the top header row of the 2nd column to span the rest of the columns.