virtual column Archives | phpGrid - PHP Datagrid Create PHP grids in minutes, not hours. Fri, 06 Dec 2024 04:06:17 +0000 en-US hourly 1 CodeProjecthttps://wordpress.org/?v=7.0.3 129966043 Save Data in Virtual Column https://phpgrid.com/example/save-data-in-calculatedvirtual-column-to-database/ Tue, 24 Feb 2015 08:16:39 +0000 http://phpgrid.com/?p=3500 It’s possible to save data in virtual column to database.To save data in virtual column or calculated column back to database, you can use jqGridAddEditAfterSubmit event (FORM edit only) to post data to another script through a separate Ajax call. The catch is you need to supply your own save data script. Just iterate the $_POST variables […]

The post Save Data in Virtual Column appeared first on phpGrid - PHP Datagrid.

]]>
It’s possible to save data in virtual column to database.To save data in virtual column or calculated column back to database, you can use jqGridAddEditAfterSubmit event (FORM edit only) to post data to another script through a separate Ajax call. The catch is you need to supply your own save data script. Just iterate the $_POST variables and call appropriate functions to save posted data to database. Should be fairly simple to do.

Below is the code snippet. Replace “orders” with your own table name please. You need to implement save_virtual_column.php to save virtual column data to another page after submit through another Ajax call

jqGridAddEditAfterSubmit works only in FORM edit mode.
X
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
$afterSubmit = <<<AFTERSUBMIT
function (event, status, postData)
{
    selRowId = $("#orders").jqGrid ('getGridParam', 'selrow');
    virtual_data1 = $("#orders").jqGrid("getCell", selRowId, 'total');   // data in virtual column
    virtual_data2 = $("#orders").jqGrid("getCell", selRowId, 'foo');
    console.log('going to post virtual column data ' + virtual_data1 + ', ' + virtual_data2 + ' to another page through a separate AJAX call');
    $.ajax({ url: 'save_virtual_column.php',
        data: {v_data1: virtual_data1, v_data2: virtual_data2}, // replace customerNumber with your own field name
        type: 'post',
        success: function(output) {
                    alert(output);
                }
        });

}
AFTERSUBMIT
;
$dg->add_event("jqGridAddEditAfterSubmit", $afterSubmit);

The screenshot illustrates values in virtual columns named “total” and “foo” are saved after users submit form. It posts to a file named “save_virtual_column.php” with posted form data v_data1, v_data2.

 

save_virtual_column_data

 

This is also a good technique to save any other additional data to database because it does not require modifying edit.php. Note that jqGridAddEditAfterSubmit works only in FORM edit mode.

The post Save Data in Virtual Column appeared first on phpGrid - PHP Datagrid.

]]>
3500
Inline Edit Actions Column https://phpgrid.com/example/inline-edit-actions-column/ Thu, 17 Oct 2013 17:44:53 +0000 http://phpgrid.com/?p=2647 Inline edit mode also comes with actions column with edit and delete buttons. Use add_column method to add “actions”. In formatoptions, specify the following property to display or hide edit and delete buttons: delbutton – true or false editbutton – true or false Note that when use actions column, it is not necessary to specify […]

The post Inline Edit Actions Column appeared first on phpGrid - PHP Datagrid.

]]>
Inline edit mode also comes with actions column with edit and delete buttons. Use add_column method to add “actions”. In formatoptions, specify the following property to display or hide edit and delete buttons:

  • delbutton – true or false
  • editbutton – true or false

Note that when use actions column, it is not necessary to specify edit options in enable_edit method. An advantage using actions column is that it’s possible to have row-level permission. Please see datagrid row-level edit permission example.

1
2
3
// 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");

// enable edit - but no need to specify 2nd parameter because we will be using actions column
$dg -> enable_edit("INLINE");

$dg->add_column("actions", array('name'=>'actions',
    'index'=>'actions',
    'width'=>'70',
    'formatter'=>'actions',
    'formatoptions'=>array('keys'=>true, 'editbutton'=>true, 'delbutton'=>false)),'Actions');

$dg -> display();

See Live Example!

The post Inline Edit Actions Column appeared first on phpGrid - PHP Datagrid.

]]>
2647
Virtual/Calculated Column https://phpgrid.com/example/virtual-column-aka-calculated-column/ Tue, 08 Jan 2013 23:18:48 +0000 http://phpgrid.com/?p=2383 Starting version 5.5, you can now add virtual column, AKA calculated column, to your existing datagrid. Virtual, by definition, is that it doesn’t exist in the database table. It’s a calculated field created from other columns. The virtual columns are added to the END of the existing datagrid. phpGrid only adds a “virtual” column and […]

The post Virtual/Calculated Column appeared first on phpGrid - PHP Datagrid.

]]>
Starting version 5.5, you can now add virtual column, AKA calculated column, to your existing datagrid. Virtual, by definition, is that it doesn’t exist in the database table. It’s a calculated field created from other columns. The virtual columns are added to the END of the existing datagrid.

phpGrid only adds a “virtual” column and does NOT change the database table structure. Front-end user should not be able to add/change a column in your database table structure. It should be done only by a very smaller number of people such as DBA, and ultimately through a back-end database administration program.

It’s important that virtual column name is NOT an existing database column name used by PHP datagrid.
X
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
use phpCtrl\C_DataGrid;
require_once("/path/to/conf.php");  

$dg = new C_DataGrid("SELECT * FROM orders", "orderNumber", "orders");
$dg->enable_edit('INLINE');

// calculated value to be displayed in the virtual column
// n1 stores column 1 value, n2 stores column 7 value..and so on.
$col_formatter = <<<COLFORMATTER
function(cellvalue, options, rowObject){
    var n1 = parseInt(rowObject[0],10),      
        n2 = parseInt(rowObject[6],10);      
    return n1+n2;
}
COLFORMATTER;

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

See Live Example! (The last two columns “Total” and “Foo” are virtual.)

The post Virtual/Calculated Column appeared first on phpGrid - PHP Datagrid.

]]>
2383
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