conditional output Archives | phpGrid - PHP Datagrid Create PHP grids in minutes, not hours. Fri, 06 Dec 2024 04:04:31 +0000 en-US hourly 1 CodeProjecthttps://wordpress.org/?v=7.0.3 129966043 Conditional Formatting with Custom Javascript https://phpgrid.com/example/conditional-formatting-custom-javascript/ Sun, 14 Jun 2015 12:43:47 +0000 http://phpgrid.com/?p=9003

What would you do if you need more than set_conditional_format() and set_conditional_value() for conditional display such as comparing two cells and set background of another cell based on the results? The answer is custom javascript. The following snippet demonstrates how to use event handler to compare values between datagrid cells. Finally it changes another cell’s […]

The post Conditional Formatting with Custom Javascript appeared first on phpGrid - PHP Datagrid.

]]>

What would you do if you need more than set_conditional_format() and set_conditional_value() for conditional display such as comparing two cells and set background of another cell based on the results? The answer is custom javascript.

The following snippet demonstrates how to use event handler to compare values between datagrid cells. Finally it changes another cell’s background color to gold.

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
// Always include namespace and conf.php on TOP of the script.
use phpCtrl\C_DataGrid;
require_once("/path/to/conf.php");  

$onGridLoadComplete = <<<ONGRIDLOADCOMPLETE
function(status, rowid)
{
    var ids = jQuery("#orders").jqGrid('getDataIDs');
    for (var i = 0; i < ids.length; i++)
    {
        var rowId = ids[i];
        var rowData = jQuery('#orders').jqGrid ('getRowData', rowId);

        var requiredDate = new Date($("#orders").jqGrid("getCell", rowId, "requiredDate"));
        var shippedDate = new Date($("#orders").jqGrid("getCell", rowId, "shippedDate"));

        // compare two dates and set custom display in another field "status"
        if(requiredDate < shippedDate){
           
            $("#orders").jqGrid("setCell", rowId, "status", '', {'background-color':'gold'});
               
        }
    }

}
ONGRIDLOADCOMPLETE
;

$dg = new C_DataGrid("SELECT * FROM orders", "orderNumber", "orders");
$dg->set_col_hidden('comments');
$dg->add_event("jqGridLoadComplete", $onGridLoadComplete);

$dg -> display();

Launch Demo!

The post Conditional Formatting with Custom Javascript appeared first on phpGrid - PHP Datagrid.

]]>
9003
Conditional Format * https://phpgrid.com/example/conditional-format-2/ Sat, 14 Jan 2012 20:51:16 +0000 http://phpgrid.com/?p=1898 * Please note this feature is not available in Lite and Basic versions.     Conditional formatting example using set_conditional_format() method. 12345678910111213141516171819// Always include namespace and conf.php on TOP of the script. use phpCtrl\C_DataGrid; require_once("/path/to/conf.php");   $dg = new C_DataGrid("SELECT * FROM orders", "orderNumber", "orders"); //Format a cell based on the specified condition$dg->set_conditional_format("orderNumber","CELL",array(     […]

The post Conditional Format * appeared first on phpGrid - PHP Datagrid.

]]>
* Please note this feature is not available in Lite and Basic versions.

 

conditional_format_ss

 

Conditional formatting example using set_conditional_format() method.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// Always include namespace and conf.php on TOP of the script.
use phpCtrl\C_DataGrid;
require_once("/path/to/conf.php");  

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

//Format a cell based on the specified condition
$dg->set_conditional_format("orderNumber","CELL",array(
    "condition"=>"eq","value"=>"10107","css"=> array("color"=>"#ffffff","background-color"=>"green")));

$dg->set_conditional_format("customerNumber","CELL",array(
    "condition"=>"eq","value"=>"141","css"=> array("color"=>"red","background-color"=>"#DCDCDC")));

// Format a row based on the specified condition
$dg->set_conditional_format("comments","ROW",array(
    "condition"=>"cn","value"=>"request","css"=> array("color"=>"white","background-color"=>"#4297D7")));    
                     
$dg->set_multiselect(true);
$dg -> display();

See Live Example!

Note:
For even more complex conditions, please refer to row level permission example by using set_grid_property() and add_event() method.

The post Conditional Format * appeared first on phpGrid - PHP Datagrid.

]]>
1898
Conditional Value * https://phpgrid.com/example/conditional-value/ Sat, 14 Jan 2012 20:08:01 +0000 http://phpgrid.com/?p=1873 * Please note this feature is not available in Lite and Basic versions. Conditional Value is similar to conditional format (see set_conditional_format) but with simpler set of features. Use set_conditional_value() to dynamically display a value when specific condition is met. The conditional value can be text, HTML, or even CSS style. You can use conditional […]

The post Conditional Value * appeared first on phpGrid - PHP Datagrid.

]]>
* Please note this feature is not available in Lite and Basic versions.

Conditional Value is similar to conditional format (see set_conditional_format) but with simpler set of features. Use set_conditional_value() to dynamically display a value when specific condition is met. The conditional value can be text, HTML, or even CSS style.

You can use conditional value with data bar in the same grid.

1
2
3
4
5
6
7
8
.tstyle
{
display:block;background-image:none;margin-right:-2px;margin-left:-2px;height:14px;padding:5px;background-color:green;color:navy;font-weight:bold
}
.fstyle
{
display:block;background-image:none;margin-right:-2px;margin-left:-2px;height:14px;padding:5px;background-color:yellow;color:navy
}

PHP Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Always include namespace and conf.php on TOP of the script.
use phpCtrl\C_DataGrid;
require_once("/path/to/conf.php");  

$dg = new C_DataGrid("SELECT * FROM joborders", "jobNumber", "joborders");
$dg -> set_col_title("jobNumber", "Job Number");
$dg -> set_col_title("jobDescription", "Description");
$dg -> set_col_title("status", "Status");              
$dg -> set_col_title("percentComplete", "Progress (%)");
$dg -> set_col_title("isClosed", "Closed");
 
$dg->set_conditional_value("isClosed", "==1", array(
    "TCellValue"=>"<img src='SampleImages/checked.gif' />",
    "FCellValue"=>"<img src='SampleImages/unchecked.gif' />"));
 
$dg->set_conditional_value("status", "=='Complete'", array(
    "TCellStyle"=>"tstyle",
    "FCellStyle"=>"fstyle"));
 
$dg->enable_edit('INLINE', 'CRUD');
 
$dg->set_multiselect(true);
$dg -> set_databar("percentComplete","red");
$dg -> display();

See Live Example!

Note:
For even more complex conditions, please refer to row level permission example by using set_grid_property() and add_event() method.

The post Conditional Value * appeared first on phpGrid - PHP Datagrid.

]]>
1873