Added a percentage formatting type to jqGrid.

git-svn-id: file:///svn-source/pmgr/branches/pre_0.1_work_20090819@787 97e9348a-65ac-dc4b-aefc-98561f571b83
This commit is contained in:
abijah
2009-08-26 19:51:06 +00:00
parent 80fe5ca4de
commit 1e34cc1de8
4 changed files with 53 additions and 13 deletions

View File

@@ -67,10 +67,16 @@ class UnitSizesController extends AppController {
* to jqGrid.
*/
function gridDataTables(&$params, &$model) {
function gridDataCountTables(&$params, &$model) {
return array('link' => array('UnitType'));
}
function gridDataTables(&$params, &$model) {
$tables = $this->gridDataCountTables($params, $model);
$tables['link']['Unit'] = array();
return $tables;
}
function gridDataFields(&$params, &$model) {
$fields = parent::gridDataFields($params, $model);
$fields[] = 'ROUND(UnitSize.width/12, 1) AS width';
@@ -80,6 +86,14 @@ class UnitSizesController extends AppController {
$fields[] = 'ROUND(UnitSize.width/12 * UnitSize.depth/12 * UnitSize.height/12, 0) AS cuft';
$fields[] = 'ROUND(UnitSize.rent / (UnitSize.width/12 * UnitSize.depth/12), 2) AS sqcost';
$fields[] = 'ROUND(UnitSize.rent / (UnitSize.width/12 * UnitSize.depth/12 * UnitSize.height/12), 2) AS cucost';
$fields[] = 'COUNT(Unit.id) AS units';
$fields[] = 'SUM(IF(' . $this->UnitSize->Unit->conditionUnavailable() . ', 1, 0)) AS unavailable';
$fields[] = 'SUM(IF(' . $this->UnitSize->Unit->conditionAvailable() . ', 1, 0)) AS available';
$fields[] = 'SUM(IF(' . $this->UnitSize->Unit->conditionOccupied() . ', 1, 0)) AS occupied';
$fields[] = 'SUM(IF(' . $this->UnitSize->Unit->conditionOccupied() . ', 0, 1)) / COUNT(unit.id) AS vacancy';
$fields[] = 'SUM(IF(' . $this->UnitSize->Unit->conditionOccupied() . ', 1, 0)) / COUNT(unit.id) AS occupancy';
return $fields;
}

View File

@@ -132,6 +132,7 @@ class Unit extends AppModel {
}
function available($enum) { return $this->vacant($enum); }
function conditionAvailable() { return $this->conditionVacant($enum); }
/**************************************************************************

View File

@@ -121,6 +121,11 @@ foreach ($jqGridColumns AS $header => &$col) {
// No special formatting for number
unset($col['formatter']);
}
elseif ($col['formatter'] === 'percentage') {
$col['formatter'] = array('--special' => 'percentageFormatter');
$default['width'] = 60;
$default['align'] = 'right';
}
elseif ($col['formatter'] === 'currency') {
// Use our custom formatting for currency
$col['formatter'] = array('--special' => 'currencyFormatter');
@@ -259,12 +264,25 @@ $jqGrid_setup = array_merge
<script type="text/javascript"><!--
jQuery(document).ready(function(){
currencyFormatter = function(cellval, opts, rowObject) {
currencyFormatter = function(cellval, opts, rowObject) {
if (!cellval)
return "";
return fmtCurrency(cellval);
}
percentageFormatter = function(cellval, opts, rowObject) {
var precision;
if (typeof(opts.colModel) != 'undefined' &&
typeof(opts.colModel.formatoptions) != 'undefined' &&
typeof(opts.colModel.formatoptions.precision) != 'undefined')
precision = opts.colModel.formatoptions.precision;
else
precision = 0;
amount = cellval.toString().replace(/\%/g,'');
amount = (amount*100).toFixed(precision);
return amount+'%';
}
idFormatter = function(cellval, opts, rowObject) {
if (!cellval)
return cellval;

View File

@@ -2,17 +2,24 @@
// Define the table columns
$cols = array();
$cols['Size'] = array('index' => 'UnitSize.name', 'formatter' => 'shortname');
$cols['Width'] = array('index' => 'UnitSize.width', 'formatter' => 'number');
$cols['Depth'] = array('index' => 'UnitSize.depth', 'formatter' => 'number');
$cols['Height'] = array('index' => 'UnitSize.height', 'formatter' => 'number');
$cols['Area'] = array('index' => 'sqft', 'formatter' => 'number');
$cols['Volume'] = array('index' => 'cuft', 'formatter' => 'number');
$cols['Deposit'] = array('index' => 'UnitSize.deposit', 'formatter' => 'currency');
$cols['Rent'] = array('index' => 'UnitSize.rent', 'formatter' => 'currency');
$cols['A. Cost'] = array('index' => 'sqcost', 'formatter' => 'currency');
$cols['V. Cost'] = array('index' => 'cucost', 'formatter' => 'currency');
$cols['Comment'] = array('index' => 'Unit.comment', 'formatter' => 'comment');
$cols['Size'] = array('index' => 'UnitSize.name', 'formatter' => 'shortname');
$cols['Width'] = array('index' => 'UnitSize.width', 'formatter' => 'number');
$cols['Depth'] = array('index' => 'UnitSize.depth', 'formatter' => 'number');
$cols['Height'] = array('index' => 'UnitSize.height', 'formatter' => 'number');
$cols['Area'] = array('index' => 'sqft', 'formatter' => 'number');
$cols['Volume'] = array('index' => 'cuft', 'formatter' => 'number');
$cols['Deposit'] = array('index' => 'UnitSize.deposit', 'formatter' => 'currency');
$cols['Rent'] = array('index' => 'UnitSize.rent', 'formatter' => 'currency');
$cols['A. Cost'] = array('index' => 'sqcost', 'formatter' => 'currency');
$cols['V. Cost'] = array('index' => 'cucost', 'formatter' => 'currency');
$cols['Unavailable'] = array('index' => 'unavailable', 'formatter' => 'number');
$cols['Occupied'] = array('index' => 'occupied', 'formatter' => 'number');
$cols['Available'] = array('index' => 'available', 'formatter' => 'number');
$cols['Total'] = array('index' => 'units', 'formatter' => 'number');
$cols['Occupancy'] = array('index' => 'occupancy', 'formatter' => 'percentage', 'formatoptions' => array('precision' => 3));
$cols['Vacancy'] = array('index' => 'vacancy', 'formatter' => 'percentage');
$cols['Comment'] = array('index' => 'Unit.comment', 'formatter' => 'comment');
// Render the grid
$grid