cfgrid format="html" how to format number?


I am using coldfusion and cfgrid, need to format a currency field with $.  Both numberformat and mask are not working.  Can this be done?  the cfgrid format="html".

Who is Participating?
_agx_Connect With a Mentor Commented:
I believe "numberFormat" only applies to applets, and "mask" to flash grids

If you're populating the grid from a query, you could format the numbers in your db query.  For CF8 you could also use the underlying Ext functions, like Ext.util.Format.usMoney ie $xx.xx format

Credit for the adaptation goes to

<cfset sampleData = QueryNew("")>
<cfset queryAddColumn(sampleData, "MoneyAmount", "Decimal", listToArray("10,15.98,90.800"))>

   <!--- create javascript function for rendering dates --->
   <script language="JavaScript" type="text/javascript">
   updateCellRenderer = function(){
      mygrid = ColdFusion.Grid.getGridObject('MyGrid');
      cm = mygrid.getColumnModel();
      // column indexes are zero based, not 1-based like in CF 
      cm.setRenderer(0, Ext.util.Format.usMoney );


<!--- Set up the Grid --->
<cfform id="MyForm" name="MyForm">
	<cfgrid name="MyGrid" format="html" pagesize="10" striperows="yes" query="sampleData">
		<cfgridcolumn name="MoneyAmount"  header="Money Amount">
<!--- use AjaxOnLoad to set the currency renderer --->
<cfset ajaxOnLoad("updateCellRenderer")>

Open in new window

RickEpnetConnect With a Mentor Commented:
Try doing the formatting in the SQL Select statement. Which SQL are you using?
jfreeman2010Author Commented:
I am using T-SQL which it will work as:

'$'+ CONVERT(VARCHAR(12), SUM(TOTAL_CHARGES), 1) on the field that need to be format.

I will try  Ext.util.Format.usMoney ie $xx.xx forma also.

jfreeman2010Author Commented:
Thank you both of your help!!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.