Formatter supports advanced formatting of the contents of cells in form, in-line and cell editing.
Formatter can be used in either of two ways: Predefined and Custom.
Here we describe the predefined formatters.

Default formatting functions are defined in the language files e.g., grid.locale-xx (where xx is your language). That mean that these formatter options are loaded when the grid java script files are loaded. See here

The default formatter options are different for different language files.

In the language file you will find all the settings that you may want to review or change before using the predefined formats. These settings can also be overridden for specific columns using the formatoptions parameter in colModel.

The second step is to set the desired formatting in colModel. This is done using the option formatter. For example.

<?php
....
$grid->setColModel(...);
$grid->setColProperty('somefield',array("formatter"=>"number"));
...

$grid->renderGrid(...);
...
?>

will format the contents of the 'somefield' column according to the rules set for 'number' in the active language file. For example, if the source value is “1234.1”, then the value that actually will be put in the grid will be “1 234.10” using the options above.

Column Specific Options

Formatter options can be defined for particular columns, overwriting the defaults from the language file. This is accomplished by using the formatoptions array in colModel. For example:

<?php
....
$grid->setColModel(...);
$grid->setColProperty('somefield',array("formatter"=>"currency", "formatoptions"=>array("prefix"=>"$ ")));
...

$grid->renderGrid(...);
...
?>

This definition will overwrite the default one from the language file. In formatoptions should be placed values appropriate for the particular format type

All predefined types are compatible with the editing modules. This means that the numbers, links, e-mails, etc., are converted so that they can be edited correctly.

Below is a list of the predefined format types

Type

Options

Description

integer

thousandsSeparator,
defaulValue

thousandsSeparator determines the separator for the thousands, defaultValue set the default value if nothing in the data

number

decimalSeparator,
thousandsSeparator,
decimalPlaces,
defaulValue

thousandsSeparator determines the separator for the thousands, decimalSeparator determines the separator for the decimals, decimalPlaces determine how many decimal places we should have for the number, defaultValue set the default value if nothing in the data

currency

decimalSeparator,
thousandsSeparator,
decimalPlaces,
defaulValue,
prefix,
suffix

The same as number, but we add aditional two options - prefix a text the is puted before the number and suffix the text that is added after the number

date

srcformat,
newformat

srcformat is the source format - i.e. the format of the date that should be converted, newformat is the new output format. The definition of the date format uses the PHP conversions. Also you can use a set of predefined date format - see the mask options in the default date formatting set

email

none

When a mail type is used we directly add a href with mailto: before the e-mail

link

target

The default value of the target options is null. When this options is set, we construct a link with the target property set and the cell value put in the href tag.

showlink

baseLinkUrl,
showAction,
addParam,
target,
idName

baseLinkUrl is the link.
showAction is an additional value which is added after the baseLinkUrl.
addParam is an additional parameter that can be added after the idName property.
target, if set, is added as an additional attribute.
idName is the first parameter that is added after the showAction. By default, this is id,

checkbox

disabled

The default value for the disabled is true. This option determines if the checkbox can be changed. If set to false, the values in checkbox can be changed

select

none

this is not a real select but a special case. See note below


There is a special type formatter called "actions".
With help of this formatter it is possible to place edit and delete buttons in certain column. These buttons are placed at each row so that if pressed the recod can be editred or deleted.
A inline editing is used when this formatter is set.
Below are the options available which can be set in formatoptions property.
Example:

$grid->addCol(array( "name"=>"actions", "formatter"=>"actions", "editable"=>false, "sortable"=>false, "resizable"=>false, "fixed"=>true, "width"=>60, "formatoptions"=>array("keys"=>true) ), "first");

Options available:

Option

Type

Description

Default

keys

boolean

When eset to false enables saving a record with pressing a Enter key

false

editbutton

boolean

When set to false disable editing

true

delbutton

boolean

When set to false disables the delet button

true

onEdit

function (javascript)

This event raises immediatley after editing the record - i.e the inlut fields are constructed. Prameters passed to this event is the rowid

null

onSuccess

function (javascript)

if defined, this function is called immediately after the request is successful. This function is passed the data returned from the server. Depending on the data from server; this function should return true or false

null

afterSave

function (javascript)

if defined, this function is called after the data is saved to the server. Parameters passed to this function are the rowid and the response from the server request.

null

onError

function (java script))

if defined, this function is called when ajax error occur. Parameters passed to this function are the rowid and the the response from the server request.

null

afterRestore

function

if defined, this function is called in restoreRow (in case the row is not saved ) method after restoring the row. To this function we pass the rowid

null

url

String

if defined, this parameter replaces the editurl parameter from the options array.

Empty

delOptions

array

A set of delete options - See For editing Deleting

null