set_col_property()

  • Parameters:
  • Description:
    •  This method allows you to directly manipulate column properties.  Since column properties are an array, you can directly change the properties. This is more “closer to the metal” for users who are already familiar with jqGrid colMdel API.
  • Remark:
    • This is an advanced method. In most cases, you don’t need to call this method.  It does not replace existing helper functions such as set_col_date, set_col_currency, etc. We suggest you use those helper functions if you are new to phpGrid.
    • This method is also used to create custom formatter. See a custom formatter example using this method.
  • Example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
$dg -> set_col_property("orderNumber", array("name"=>"Order Number", "width"=>40));
$dg -> set_col_property("orderDate", 
                             array("formatter"=>"date",
                                   "formatoptions"=>array("srcformat"=>"Y-m-d","newformat"=>"m/d/Y")));  // display different time format

// Display time only. No date. It cannot be edited, so we also made it hidden on the edit form.
$dg -> set_col_property("shippedDate",
            array("formatter"=>"date",
                "formatoptions"=>array("srcformat"=>"ISO8601Short","newformat"=>"g:i A"),
                'editable'=>false,'hidedlg'=>true));

// currency format
$dg -> set_col_format("quantityInStock", "integer", array("thousandsSeparator" => ",",
                                                          "defaultValue" => "0"));  
$dg -> set_col_format("MSRP", 'currency', array("prefix" => "$",
                                                "suffix" => '',
                                                "thousandsSeparator" => ",",
                                                "decimalSeparator" => ".",
                                                "decimalPlaces" => 2,
                                                "defaultValue" => '0.00'));

Custom Formatter/Unformatter Example

PHP

1
2
3
4
5
6
7
$dg -> set_col_property('rating',
        array("classes"=>'ratingcol',
            "sorttype"=>"number",
            "formatter"=>"###ratingformatter###",
            "unformat"=>"###unformathtml###"));

...

JavaScript

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// Formatter JavaScript
function ratingformatter(cellValue, options, rowdata)
{
    output = '';
    width = Math.max(2, 14 * Math.min(5, Math.max(0, cellValue)));
    output += '<div class="accRatingBar" style="width:' + width + 'px;"></div>';
    output += '<p class="accRatingText">' + cellValue + '</p>';
    output += "<!--" + cellValue + "-->";
    return output;
}

// The corresponding unformatter JavaScript function
function unformathtml(cellValue, options, cellObject)
{
    html = $(cellObject).html();
    quotestart = html.indexOf("<!--");
    if (quotestart == -1)
    return html;
    quoteend = html.indexOf("-->");
    output = html.substring(quotestart + 4, quoteend);
    return output;
}