set_col_format()

  • Parameter(s):
    • $col_name: Datagrid column name
    • $format: The format types are:
      • integer
      • number
      • email
      • link
      • showlink
      • currency
      • date
      • checkbox
      • select
    • $formatoptions: PHP array stores format options of different formatting.
  • Description:
    • Although this method is purely for cosmetic purpose, it is very useful and also practical in many situations when displaying different type of data.
    • Depending on the type of format, it could have different format options. In most cases, users only need to set column formatting for “integer”, “number”, and “mail” using this method. For “currency’, “link”, and “showlink” formats, phpGrid provides a number of helper functions to make formatting simpler and easier. They are
    • The helper functions will be covered later in the documentation.
    • For type “date”, users don’t have to do anything for formatting. The format is automatically set to “date” when the database data field type is date or datetime.
    • In addition, the formats are automatically set as “checkbox” or “select” if the edit type is checkbox or select defined in set_col_edittype().
  • Remark:
    • Though all of the formattings can be done in this method, it is recommended to use helper functions whenever possible.¬†phpGrid ensures the formatting is automated as much as possible. Automation means less coding, and thus less room for error.¬†Simplicity is what phpGrid strives for.
    • To create custom formatter, please see set_col_property advanced method. Some javascript knowledge is required.
  • Example:
1
2
3
$dg -> set_col_format('quantity','integer', array('thousandsSeparator'=>',', 'defaultValue'=>'0'));
$dg -> set_col_format("emailAddress", "email");
$dg -> set_col_format("weight", 'number', array("thousandsSeparator" => ",", "decimalSeparator" => ".", "decimalPlaces" => '2', "defaultValue" => '0.00'));

No related content found.