Hi,
How can I do the following:
I have a table with various fields, amongst which:
operation (value C for Credit, D for Debit)
amount (always saved with positive value)
When retrieve data and displaying them, I would like the amount to be NEGATIVE when operation = D else positive.
Then I would use it for calculating correct running balance.
Thanks
Hello,
One option is to use IF() condition in SQL (select_command) and make that value negative. IF(operation='D',amount*-1,amount)
Second option is to use on_data_display event handler and write you custom code to change values before they are displayed on grid.
You can refer demos/appearance/calc-column.php for help.
Hi Abu,
I did actually use the following code:
$col = array();
$col["title"] = "Montant";
$col["name"] = "cbt_montant";
$col["width"] = "30";
$col["editable"] = true; // this column is not editable
$col["align"] = "center"; // this column is not editable
$col["search"] = true; // this column is not searchable
$col["hidden"] = false; // HIDE this column
$col["on_data_display"] = array("display_keyword","");
function display_keyword($data)
{
$op = $data["cbt_operation"];
$montant = $data["cbt_montant"];
if ($op == 'D') {$nouveau_montant = number_format(-$montant,2, '.',''); return $nouveau_montant;}
else {return $montant;}
}
$cols[] = $col;