Get KoolPHP UI with 30% OFF!

How to format number [with thousand separator] displayed in InfoField of a GroupField?

Igor
Hi,
how to format number [with thousand separator] displayed in InfoField of a GroupField?
I tried with this chunk:
	$group = new GridGroup();
	$group->Expand = true; //Collapse
	$group->GroupField = "molecule";
	// $group->HeaderText = "";
	$group->AddInfoField("sVol_16","sum");
	$group->InfoTemplate = "Total 2016: {sVol_16} $";
	$group->ThousandSeperate = "."; 
	$grid->MasterTable->AddGroup($group); 

Posted Oct 13, 2017 , edited Oct 17, 2017 Kool
Anthony Amolochitis
Use the grid pre render to create it.
// Add this to your row prerender event
$row->DataItem['sVol_16_formatted'] = number_format( $row->DataItem['sVol_16'] , 0 , '.' , ',' ) ;
.....
.....
// use it in your group
$group = new GridGroup();
$group->Expand = true; //Collapse
$group->GroupField = "molecule";
// $group->HeaderText = "";
$group->AddInfoField("sVol_16_formatted","sum");
$group->InfoTemplate = "Total 2016: {sVol_16_formatted} $";
$group->ThousandSeperate = ".";
$grid->MasterTable->AddGroup($group);
Posted Oct 14, 2017 Kool
Igor
	class MyGridEventHandler extends GridEventHandler
	{
		function OnRowPreRender($row,$args)
		{
			$row->DataItem['sVol_16format'] = number_format($row->DataItem['sVol_16'], 0,'.', ',');
		}
	}
	$grid->EventHandler = new MyGridEventHandler();
	$group = new GridGroup();
	$group->Expand = true; //Collapse
	$group->GroupField = "molecule";
	$group->HeaderText = "";
	$group->AddInfoField("sVol_16format","sum");
	$group->InfoTemplate = "Total 2016: {sVol_16format} $";
	// $group->ThousandSeperate = "."; // Display 1'000.53 instead of 1,000.53
	// $group->DecimalNumber = 0;
	$grid->MasterTable->AddGroup($group); 	

Warning: Invalid argument supplied for foreach()
, and if I take "sum" aggregator out from [$group->AddInfoField("sVol_16format","sum");] I get this:

it's the value of first row, not the sum of the groupfield [molecule].
I think that after number_format is applied on [sVol16_format] value, [string $aggregate] value produces this error:
Warning: Invalid argument supplied for foreach()
Posted Oct 14, 2017 , edited Oct 14, 2017 Kool
Anthony Amolochitis
I had mistakenly thought you were using a grid column.
You are taking a sum and displaying it elsewhere.
That would have worked for displaying row values as formatted numbers.
Seems like a job for KoolPHP. You should submit a ticket to them.
Please let me know what they say. I'm curious on how to handle this issue.
Posted Oct 14, 2017 , edited Oct 14, 2017 Kool
Igor
Hi,
I found a pretty nice solution for showing more than one calculated field in InfoField of a GroupField.
Now I have two more problems to solve:
1. trying to align the content of InfoField with the width of a column of the data table
2. number format in InfoField [thousand separator]

$group = new GridGroup();
	$group->Expand = true; //Collapse
	$group->GroupField = "manufacturer";
	$group->HeaderText = "";
	$group->AddInfoField("TotalVol15", "sum"); 
	$group->AddInfoField("TotalVol16", "sum");
	$group->AddInfoField("TotalSales15", "sum");
	$group->AddInfoField("TotalSales16", "sum");
	$group->AddInfoField("TrendVolume");
	$group->AddInfoField("TrendSales");
	$group->AddInfoField("manufacturer");
	$group->AddInfoField("mSh16");
	$group->InfoTemplate = 
	"{manufacturer}, || Vol15: {TotalVol15} $, || Vol16: {TotalVol16} $, || Sal15: {TotalSales15} $, || Sal16: {TotalSales16} $,  || TVol: {TrendVolume}, || TSal: {TrendSales} $, || mShare: {mSh16} %";
	$group->ThousandSeperate = "."; // Display 1'000.53 instead of 1,000.53
	$group->DecimalNumber = 0;
	$grid->MasterTable->AddGroup($group);
Posted Nov 25, 2017 , edited Nov 25, 2017 Kool