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:
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user