summaryrefslogtreecommitdiff
path: root/framework/Web/UI/WebControls/TDataGridColumn.php
diff options
context:
space:
mode:
authorwei <>2006-04-25 01:00:08 +0000
committerwei <>2006-04-25 01:00:08 +0000
commitc84f3e19b54cf54f525f4b2d158696ae32d1bf60 (patch)
tree60720fba29ef72175db47dd3cd4b74d8bbed605b /framework/Web/UI/WebControls/TDataGridColumn.php
parent09edc6590523e26fffbf32f7b0e7958c166f7537 (diff)
Add TListControlValidator. Update client-side validators, datepicker.js, colorpicker.js.
Diffstat (limited to 'framework/Web/UI/WebControls/TDataGridColumn.php')
-rw-r--r--framework/Web/UI/WebControls/TDataGridColumn.php30
1 files changed, 25 insertions, 5 deletions
diff --git a/framework/Web/UI/WebControls/TDataGridColumn.php b/framework/Web/UI/WebControls/TDataGridColumn.php
index de9d9d5c..e43b4895 100644
--- a/framework/Web/UI/WebControls/TDataGridColumn.php
+++ b/framework/Web/UI/WebControls/TDataGridColumn.php
@@ -11,7 +11,7 @@
*/
/**
- * Includes TDataFieldAccessor class
+ * Includes TDataFieldAccessor and TDataValueFormatter classes
*/
Prado::using('System.Util.TDataFieldAccessor');
@@ -331,17 +331,37 @@ abstract class TDataGridColumn extends TApplicationComponent
}
/**
- * Formats the text value according to format string.
- * This method invokes the {@link sprintf} to do string formatting.
+ * Formats the text value according to a format string.
* If the format string is empty, the original value is converted into
* a string and returned.
+ * If the format string starts with '#', the string is treated as a PHP expression
+ * within which the token '{0}' is translated with the data value to be formated.
+ * Otherwise, the format string and the data value are passed
+ * as the first and second parameters in {@link sprintf}.
* @param string format string
- * @param mixed the data associated with the cell
+ * @param mixed the data to be formatted
* @return string the formatted result
*/
protected function formatDataValue($formatString,$value)
{
- return $formatString===''?TPropertyValue::ensureString($value):sprintf($formatString,$value);
+ if($formatString==='')
+ return TPropertyValue::ensureString($value);
+ else if($formatString[0]==='#')
+ {
+ $expression=strtr(substr($formatString,1),array('{0}'=>'$value'));
+ try
+ {
+ if(eval("\$result=$expression;")===false)
+ throw new Exception('');
+ return $result;
+ }
+ catch(Exception $e)
+ {
+ throw new TInvalidDataValueException('datagridcolumn_expression_invalid',get_class($this),$expression,$e->getMessage());
+ }
+ }
+ else
+ return sprintf($formatString,$value);
}
}