Advanced Archives | phpGrid - PHP Datagrid Create PHP grids in minutes, not hours. Tue, 03 Dec 2024 22:53:14 +0000 en-US hourly 1 CodeProjecthttps://wordpress.org/?v=7.0.3 129966043 set_grid_property() https://phpgrid.com/documentation/set_grid_property/ Fri, 11 Oct 2013 21:27:47 +0000 http://phpgrid.com/?p=2606 Parameters: $grid_property: An array represents grid property. The property will add to or overwrite existing PHP data grid properties. List of available grid properties (http://www.trirand.com/jqgridwiki/doku.php?id=wiki:options) Description:  Advanced method that  sets datagrid properties. The parameter must be an array. You must be rather familiar jqGrid API in order to take advantage of this method effectively. In most […]

The post set_grid_property() appeared first on phpGrid - PHP Datagrid.

]]>
  • Parameters:
  • Description:
    •  Advanced method that  sets datagrid properties. The parameter must be an array. You must be rather familiar jqGrid API in order to take advantage of this method effectively. In most cases, you do not need to use this method.
  • Remark:
    • This method is completely difference from set_col_property() method that sets column property, a subset of grid property.
    • This is an advanced method. In most cases, you don’t need to call this method.
  • Example:
  • 1
    2
    3
    $dg -> set_grid_property(array('search'=>true));
    $dg -> set_grid_property(array('direction'=>'rtl'));
    $dg -> set_grid_property(array("altclass" => "alternatie_row_css_class"));

    custo_prop_jsonstr or set_grid_property?

    The difference between cust_prop_jsonstr and set_grid_property is that the later is a function and must take an array as parameter but cust_prop_jsonstr takes string parameter.

    Which one to use?

    The rule of thumb is to use cust_prop_jsonstr when the property is form of string; else use set_grid_property() function. In general, you want to use set_grid_property().

    The post set_grid_property() appeared first on phpGrid - PHP Datagrid.

    ]]>
    2606
    $cust_prop_jsonstr https://phpgrid.com/documentation/cust_prop_jsonstr/ Fri, 11 Oct 2013 19:10:31 +0000 http://phpgrid.com/?p=2605 $custo_prop_jsonstr is a variable, not a function. The variable type is JSONString (string in JSON format). The difference between $cust_prop_jsonstr and set_grid_property() is that the later is a function and must take an array as parameter. On the other hand, $cust_prop_jsonstr gives user the power to inject string directly into the jQgrid properties. Which one […]

    The post $cust_prop_jsonstr appeared first on phpGrid - PHP Datagrid.

    ]]>
    $custo_prop_jsonstr is a variable, not a function. The variable type is JSONString (string in JSON format).

    The difference between $cust_prop_jsonstr and set_grid_property() is that the later is a function and must take an array as parameter. On the other hand, $cust_prop_jsonstr gives user the power to inject string directly into the jQgrid properties.

    Which one to use?

    The rule of thumb is to use $cust_prop_jsonstr when the property is form of string; else use set_grid_property() function. In general, you want to use set_grid_property().

    Remark:

    This is an advanced variable. In most cases, you do not need to use it unless you are already very familiar with jQgrid ins and outs that you want to manipulate your grid properties like a code ninja. :)

    Example:

    1
    2
    3
    4
    5
    // Here filters must be passed as string to data.php later sent through POST. It's not possible to use set_grid_property function which must take array params
    $dg->cust_prop_jsonstr .= 'postData: {filters:
                                \'{"groupOp":"AND","rules":[{"field":"status","op":"eq","data":"Shipped"}]}\'},'
    ;
    // add toolbar to top of the grid.
    $dg->cust_prop_jsonstr .= 'toppager:true,';

    The post $cust_prop_jsonstr appeared first on phpGrid - PHP Datagrid.

    ]]>
    2605
    before_script_end https://phpgrid.com/documentation/before_script_end/ Fri, 11 Oct 2013 18:40:15 +0000 http://phpgrid.com/?p=2603 before_script_end is not a function but a variable. It allows you to inject custom javascript before the end of jqGrid object closing script tag so all DOM elements are presented. This is considered an advanced way to manipulate your grid. The following code snippet demonstrates using this variable to insert a javascript that creates a […]

    The post before_script_end appeared first on phpGrid - PHP Datagrid.

    ]]>
    before_script_end is not a function but a variable. It allows you to inject custom javascript before the end of jqGrid object closing script tag so all DOM elements are presented. This is considered an advanced way to manipulate your grid.

    The following code snippet demonstrates using this variable to insert a javascript that creates a export dropdown menu on the bottom toolbar.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    $dg3 = new C_DataGrid("SELECT * FROM products", "productCode", "products");

    $exportDropdown =<<< EXPORTDROPDOWN
    $('#products_pager1_left').append ('<div style=padding-right: 16px;>Export:\
        <select onchange=document.location.href=this.options[this.selectedIndex].value;>\
            <option>---</option>\
            <option value=/phpGridx/export.php?gn=products&export_type=excel>Excel</option>\
            <option value=/phpGridx/export.php?gn=products&export_type=pdf>PDF</option>\
            <option value=/phpGridx/export.php?gn=products&export_type=html>HTML</option>\
            <option value=/phpGridx/export.php?gn=products&export_type=csv>CSV</option>\
        </select></div>');
    EXPORTDROPDOWN;

    $dg->before_script_end = $exportDropdown;
    $dg->display();

    The post before_script_end appeared first on phpGrid - PHP Datagrid.

    ]]>
    2603
    set_grid_method() https://phpgrid.com/documentation/set_grid_method/ Sat, 20 Apr 2013 21:25:24 +0000 http://phpgrid.com/?p=2450 Parameter(s): parameter: A variable argument. Variable argument makes the function more flexible because different jqGrid methods will have different set of parameters. Super useful. Description: Calling a jqGrid method to perform a specific action on the current grid. It is considered an advanced method. A list of basic methods can be found here: http://www.trirand.com/jqgridwiki/doku.php?id=wiki:methods Remark: Available in […]

    The post set_grid_method() appeared first on phpGrid - PHP Datagrid.

    ]]>
  • Parameter(s):
    • parameter: A variable argument. Variable argument makes the function more flexible because different jqGrid methods will have different set of parameters. Super useful.
  • Description:
  • Remark:
    • Available in 5.5.5 and higher.
    • Starting version 6, the parameter becomes a single variable argument.
    • Only use this method to call jqGrid methods that can act on the grid as a whole. It’s NOT possible to manipulate the grid on a row or cell level using set_grid_method because the generated javascript code is appended to the end of the script before closing bracket.
  • Example:
  • 1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    // create group header using this method
    $dg->set_grid_method('setGroupHeaders', array(
                        array('useColSpanStyle'=>true),
                        'groupHeaders'=>array(
                            array('startColumnName'=>'customerNumber',
                                'numberOfColumns'=>2,
                                'titleText'=>'Numbers Header') )));
    // inline edit add new row
    $dg->set_grid_method('inlineNav',
                    '#'. $this->jq_gridName .'_pager1',
                    array('addParams' => array(
                            'position'=> "last",
                            'addRowParams'=>array(
                            'keys'=>true))));

    The post set_grid_method() appeared first on phpGrid - PHP Datagrid.

    ]]>
    2450
    set_col_customrule() https://phpgrid.com/documentation/set_col_customrule/ Tue, 08 Jan 2013 23:33:06 +0000 http://phpgrid.com/?p=2385 Parameters: $col_name: column name $custom rule: Javascript function to validate data Description: Create custom javascript validation for column value during edit. phpGrid has automatic default validation based on database data type. This method comes in handy when additional data validation is required such as value range, data dependency etc. Example: 12// price_validation1 is a javascript […]

    The post set_col_customrule() appeared first on phpGrid - PHP Datagrid.

    ]]>
  • Parameters:
    • $col_name: column name
    • $custom rule: Javascript function to validate data
  • Description:
    • Create custom javascript validation for column value during edit. phpGrid has automatic default validation based on database data type. This method comes in handy when additional data validation is required such as value range, data dependency etc.
  • Example:
  • 1
    2
    // price_validation1 is a javascript function. See related associate live example for complete implementation
    $dg->set_col_customrule('quantityInStock', 'price_validation1'); 

    The post set_col_customrule() appeared first on phpGrid - PHP Datagrid.

    ]]>
    2385
    add_column() https://phpgrid.com/documentation/add_column/ Tue, 08 Jan 2013 23:02:56 +0000 http://phpgrid.com/?p=2380 Parameter(s): $col_name: Name of the calculated/virtual column. It cannot have space and must NOT be one of the existing database column names. $property: Column properties. See set_col_property() for available column properties usage. $title: Optional. Title for this virtual column. If omitted, it’s the same as the column name $col_name. Description: Append virtual column, AKA calculated […]

    The post add_column() appeared first on phpGrid - PHP Datagrid.

    ]]>
  • Parameter(s):
    • $col_name: Name of the calculated/virtual column. It cannot have space and must NOT be one of the existing database column names.
    • $property: Column properties. See set_col_property() for available column properties usage.
    • $title: Optional. Title for this virtual column. If omitted, it’s the same as the column name $col_name.
  • Description:
    • Append virtual column, AKA calculated column, to the end of an existing datagrid with this method.
  • Remark:
    • The $col_name cannot contain space and must begin with a letter
    • Use “formatter” column property to hook up Javascript function, e.g. below, $col_formatter is the Javascript to display value in virtual column.
    • The virtual column always adds to the end of the grid in the order of virtual column is created.
    • Text must be surrounded with SINGLE quote.
    • Virtual column is not sortable.
  • Example:
  • 1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    $col_formatter = <<<COLFORMATTER
    function(cellvalue, options, rowObject){
    var n1 = parseInt(rowObject[0],10),    // get value from column #1
    n2 = parseInt(rowObject[6],10);        // get value from column #7
    return n1+n2;    
    }
    COLFORMATTER
    ;

    $dg -> add_column(
            'total',
            array('name'=>'total',
                'index'=>'total',
                'width'=>'360',
                'align'=>'right',
                'formatter'=>$col_formatter),
            'Total (Virtual)');

    The post add_column() appeared first on phpGrid - PHP Datagrid.

    ]]>
    2380
    set_col_property() https://phpgrid.com/documentation/set_col_property/ Sat, 14 Jul 2012 17:19:26 +0000 http://phpgrid.com/?p=2161 Parameters: $col_name: column name $property: An array represents the column properties. List of available properties (http://www.trirand.com/jqgridwiki/doku.php?id=wiki:colmodel_options) 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: […]

    The post set_col_property() appeared first on phpGrid - PHP Datagrid.

    ]]>
  • 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;
    }

    The post set_col_property() appeared first on phpGrid - PHP Datagrid.

    ]]>
    2161
    Master Detail Grid * https://phpgrid.com/example/master-detail-grid/ Fri, 17 Sep 2010 04:40:01 +0000 http://64.38.236.7/?p=556 * Please note this feature is only available in Premium and higher editions. The phpGrid went extra miles to make creating the master detail datagrid a super simple task. There is essentially a simple function to set_masterdetail() to set the master detail relationship between two datagrids, and have them work interactively. The detail grid is […]

    The post Master Detail Grid * appeared first on phpGrid - PHP Datagrid.

    ]]>
    * Please note this feature is only available in Premium and higher editions.

    The phpGrid went extra miles to make creating the master detail datagrid a super simple task. There is essentially a simple function to set_masterdetail() to set the master detail relationship between two datagrids, and have them work interactively.

    The detail grid is a regular phpGrid object and can have the same methods like any other datagrid, such as description title, sort, and update etc. The detail grid renders dynamically based on the row selected in parent grid. A master grid can have one detail grid one or more detail datagrids.

    Note that you can have master and detail grids from the same database table as long as different SQL alias are used.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    // Always include namespace and conf.php on TOP of the script.
    use phpCtrl\C_DataGrid;
    require_once("/file/path/to/conf.php");  

    $dg = new C_DataGrid("SELECT * FROM Orders", "orderNumber", "Orders");

    // change column titles
    $dg->set_col_title("orderNumber", "Order No.");
    $dg->set_col_title("orderDate", "Order Date");
    $dg->set_col_title("shippedDate", "Shipped Date");
    $dg->set_col_title("customerNumber", "Customer No.");
     
    // enable edit
    $dg->enable_edit("INLINE", "CRUD");

    // hide a column
    $dg -> set_col_hidden("requiredDate");

    // read only columns, one or more columns delimited by comma
    $dg -> set_col_readonly("orderDate, customerNumber");

    // required fields
    $dg -> set_col_required("orderNumber, customerNumber");

    // multiple select
    $dg -> set_multiselect(true);
     
    // second grid as detail grid. Notice it is just another regular phpGrid with properites.
    $sdg = new C_DataGrid("SELECT orderNumber,productCode,quantityOrdered,priceEach FROM OrderDetails", "orderNumber", "OrderDetails");
    $sdg->set_col_title("orderNumber", "Order No.");
    $sdg->set_col_title("productCode", "Product Code");
    $sdg->set_col_title("quantityOrdered", "Quantity");
    $sdg->set_col_title("priceEach", "Unit Price");
    $sdg->set_col_dynalink("productCode", "http://www.example.com/", "orderLineNumber", '&foo');
    $sdg->set_col_format('orderNumber','integer', array('thousandsSeparator'=>'','defaultValue'=>''));
    $sdg->set_col_currency('priceEach','$');

    // define master detail relationship by passing the detail grid object as the first parameter, then the foriegn key name.
    $dg->set_masterdetail($sdg, 'orderNumber');

    $dg->display();

    See Live Example!


    Common Issue:
    Missing add icon in the detail grid

    The post Master Detail Grid * appeared first on phpGrid - PHP Datagrid.

    ]]>
    556