i am trying to change cell background color based on condition on particular column, it is not working.please help to me to resolve. this is what i have tried. my php page for your reference. thanks. i found a solution but it doesnt work on my php page. this that solution http://www.ok-soft-gmbh.com/jqGrid/BackgroundColorFormatter.htm
<?php
$con=mysqli_connect("localhost","user","pass","db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$val = mysqli_query($con,"select storenm,FA_SOH,FA_CY_QTY,FA_CT_QTY from pr_report");
$arr=array();
while ($row = mysqli_fetch_array($val)){
$arr[] = "["."'".$row['storenm']."'".","."'".$row['FA_SOH']."'".","."'".$row['FA_CY_QTY']."'"."]";
}
$assign = implode(',',$arr);
?>
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name=viewport content="width=device-width, initial-scale=1"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta charset="utf-8">
<!--jQuery dependencies-->
<link rel="stylesheet" href="jquery-ui.css" />
<script src="jquery-1.11.0.min.js"></script>
<script src="jquery-ui.min.js"></script>
<script type="text/javascript" src="touch-punch.min.js"></script>
<!--PQ Grid files-->
<link rel="stylesheet" href="pqgrid.min.css" />
<script src="pqgrid.min.js"></script>
<!--PQ Grid Office theme-->
<link rel="stylesheet" href="themes/office/pqgrid.css" />
<style type="text/css">
span.cellWithoutBackground
{
display:block;
background-image:none;
margin-right:-2px;
margin-left:-2px;
height:14px;
padding:4px;
}
</style>
<script>
$(function () {
var data = [<?PHP echo $assign;?>];
var obj = {
swipeModel: { on : true },
//scrollModel: { autoFit: true },
title: "Grid From JSON",
collapsible: { on: true, collapsed: false },
virtualX: false,
virtualY: false,
freezeRows: 0,
freezeCols: 1,
editable: false,
resizable: false,
width: 400,
height: 400,
title: "ParamQuery Grid Example"
};
obj.colModel = [{
title: "Storenm", width: 100, dataType: "string" },
{ title: "FSOH", width: 200, dataType: "float",align: "center" },
{ title: "FCY", width: 150, dataType: "float",align: "center",
formatter: function (cellvalue) {
var color;
var val = Number(cellvalue);
if (val>25) {
color = 'red';
} else if (val>15) {
color = 'yellow';
} else {
color = 'green';
}
return '<span class="cellWithoutBackground" style="background-color:' + color + ';">' + cellvalue + '</span>';
}
},
{ title: "Profits ($ millions)", width: 150, dataType: "float", align: "right"}];
obj.dataModel = {data: data};
$("#grid_array").pqGrid(obj);
});
</script>
</head>
<body>
<div id="grid_array" style="margin:100px;"></div>
</body>
</html>
Thanks.