Andrew Plummer - Design Development Translation

Example 14: Injecting a Column

Summary

There may be cases when the table that you want to display to the user needs to include data that isn't in the database. The injectColumn() method is included for this purpose.

Example

View Example

PHP Code

$tg = new TableGear(array( "database" => array( "username" => "USERNAME", "password" => "PASSWORD", "database" => "DATABASE", "table" => "TABLE" ), "sortable" => "all", "editable" => "all", "loading" => array( "tag" => "img", "attrib" => array( "src" => "/images/icons/loading.gif", "alt" => "Loading", "class" => "loading" ) ), "formatting" => array( "price" => "currency[prefix=$,pad], "date" => "date" ), "totals" => array("price", "quantity") ); $inject = array("one", "two", "three", "four", "five", "six", "seven", "eight"); $tg->injectColumn($inject, "first", "numbers");

In the example, we are using injectColumn() to get the data in array $inject into the table. first indicates the position in the table that we want to inject the column. This can be "first", "last", a number, or the phrases "before" or "after" with a column in square brackets following it (ie. before[price]). The final argument for injectColumn() is a name for the field. This will be turned into a header, and can be used for applying formatting and other options to that column.

Note that not all our data in $inject actually makes it into the table. This is because we have more data than we have rows, in which case the data gets truncated. For more detailed information about working with injectColumn(), see the documentation.