Table Columns

ColumnTypes

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 be serialized.
  • 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 another example.
  • 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:

  • createCallableColumn()
  • createIndexedColumn()
  • createPropertyColumn()
  • createNodeColumn()
  • createVirtualAttributeColumn()
  • createLinkColumn()

Table lets you build quite complex HTML tables, and can also serve as a base class for fully JavaScript datagrid controls such as the jqGrid and DataTables jQuery plugins.

First Example

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.

Second Example

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.

Third Example

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.

Example One

Full NameFirst NameLast Name
Full Name is "John Doe"JohnDoe
Full Name is "Kendall Public afd"KendallPublic afd
Full Name is "Ben Robinson"BenRobinson
Full Name is "Mike Ho"MikeHo
Full Name is "Alex1 Smith"Alex1Smith
Full Name is "Wendy Smith"WendySmith
Full Name is "Karen Wolfe"KarenWolfe
Full Name is "Samantha Jones"SamanthaJones
Full Name is "Linda Brady"LindaBrady
Full Name is "Jennifer Smith"JenniferSmith
Full Name is "Brett Carlisle"BrettCarlisle
Full Name is "Jacob Pratt"JacobPratt
Full Name is "51 "51
Full Name is "51 ññ"51ññ
Full Name is "51 ññ"51ññ
Full Name is "51 ññ"51ññ
Full Name is "51 ññ"51ññ
Full Name is "51 ññ"51ññ
Full Name is "51 ññ"51ññ
Full Name is "51 ññ"51ññ
Full Name is "51 ññ"51ññ
Full Name is "51 ññ"51ññ
Full Name is "51 ññ"51ññ
Full Name is "51 ññ"51ññ
Full Name is "1 2"12
Full Name is "1 2"12
Full Name is "asdf asdf"asdfasdf
Full Name is "lol k"lolk
Full Name is "lol k"lolk
Full Name is "lol k"lolk
Full Name is "lol k"lolk
Full Name is "lol k"lolk
Full Name is "lol k"lolk
Full Name is "lol k"lolk
Full Name is "lol k"lolk
Full Name is "4 asdads"4asdads
Full Name is "4 asdads"4asdads
Full Name is "4 asdads"4asdads
Full Name is "4 asdads"4asdads
Full Name is "4 asdads"4asdads
Full Name is "asdas asdads"asdasasdads
Full Name is "asdas asdads"asdasasdads
Full Name is "asdas asdads"asdasasdads
Full Name is "asdas asdads"asdasasdads
Full Name is "asdas asdads"asdasasdads

Example Two

YearModelCount
1997FordE350ac, abs, moon5
1999ChevyVenture "Extended Edition"5
1999ChevyVenture "Extended Edition, Very Large"5
1996JeepGrand CherokeeMUST SELL!4

Example Three

Year
200020012002
Income100020001500
Expense5007002100
Net5001300-600