Andrew Plummer - Design Development Translation

Example 6: Applying Data Formatting

Summary

Data formatting lets you put your data into common formats before it is sent to the browser. In the example, we are specifying a currency and a date format.

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" ) );

In this example, we are adding a currency format to the "price" field, and a date format to the "date" field. The parameters for each of these depend on the type of format. For currency we are saying that we want to add dollar sign in front of the data, and pad it out to two digits. date will be turned into a standard date format.

For more information on these options, see the documentation.