Structures_DataGrid_Column::format

Structures_DataGrid_Column::format() – Choose a format preset

Synopsis

require_once 'Structures/DataGrid/Column.php';

void Structures_DataGrid_Column::format ( $type , mixed $type,... )

Description

EXPERIMENTAL: the behaviour of this method may change in future releases.

This method allows to associate an "automatic" predefined formatter to the column, for common needs as formatting dates, numbers, ...

The currently supported predefined formatters are :

  • dateFromTimestamp: format a UNIX timestamp according to the date()-like format string passed as second argument

  • dateFromMysql : format a MySQL DATE, DATETIME, or TIMESTAMP MySQL according to the date() like format string passed as second argument

  • number: format a number, according to the same optional 2nd, 3rd and 4th arguments that the number_format() PHP function accepts.

  • printf: format using the printf expression passed as 2nd argument.

  • printfURL: url-encode and format using the printf expression passed as 2nd argument

Parameter

$type

mixed $type,...

Predefined formatter name, followed by formatter-specific parameters

Throws

throws no exceptions thrown

Examples

Common formats

<?php

// Format UNIX timestamps as english dates:
$column->format('dateFromTimestamp''m/d/y');

// Format MySQL DATE, DATETIME or TIMESTAMP strings as french dates:
$column->format('dateFromMysql''d/m/y');

// Format numbers with 3 decimals and no thousands separator:
$column->format('number'3'.''');

// Format numbers with 2 decimals:
$column->format('number'2);

// Format using a printf expression:
$column->format('printf''Number of potatoes: %d');

// Format an HTML link using a printf expression with url-encoding:
$column->format('printfURL''<a href="edit.php?key=%s">Edit</a>'); 

?>

Note

This function can not be called statically.

Constructor (Previous) Formatter (Next)
Last updated: Thu, 24 Apr 2014 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report or add a note.
View this page in:

User Notes:

There are no user contributed notes for this page.