Andrew Plummer - Design Development Translation

Example 5: Creating Incremented Select Elements

Summary

One of the cooler features of TableGear is its ability to easily create one of the more complicated HTML elements, the select element. Although you can pass TableGear an array to create a fixed select element, for numeric incremented data it is much easier to use the increment parameter.

Example

View Example

PHP Code

$tg = new TableGear(array( "database" => array( "username" => "USERNAME", "password" => "PASSWORD", "database" => "DATABASE", "table" => "TABLE" ), "sortable" => "all", "editable" => "all", "selects" => array( "price" => "increment[min=1,range=5]" ) "loading" => array( "tag" => "img", "attrib" => array( "src" => "/images/icons/loading.gif", "alt" => "Loading...", "class" => "loading" ) ) );

By specifying the minimal code in the example, we are essentially saying to TableGear that we want to create a select element to be the input for cells in the "price" column. Inside this select element, we want our option elements to be relative to the current value, with a range of 5 in either direction (so no more than 11 elements including the current value), and a minimum of 1. If we had a definite maximum value, we could also enter this as max.

When using increment, we can also specify the value step, which will make the values of the option elements "step" by that amount (for example 2, 4, 6, 8 instead of 1, 2, 3, 4 etc.). The default is 1, so we don't need to specify it here.

Finally, the select is relative to the current data by default, but if you need the select to be the same for all cells, regardless of the data inside, you can use the boolean value abs to make it absolute.