cfgrid format="html" how to format number?

Hi

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".

jfreeman2010Asked:
Who is Participating?
 
_agx_Connect With a Mentor Commented:
I believe "numberFormat" only applies to applets, and "mask" to flash grids
http://livedocs.adobe.com/coldfusion/8/htmldocs/Tags_g-h_04.html#3988181

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
http://ajaxian.com/archives/coldfusion-8-grid-magic








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

<html>
<head>
   <!--- 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 );
      mygrid.reconfigure(mygrid.getDataSource(),cm);
   }
   </script>
</head>

<body>

<!--- 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">
	</cfgrid>
</cfform>
<!--- use AjaxOnLoad to set the currency renderer --->
<cfset ajaxOnLoad("updateCellRenderer")>
	
</body>
</html>

Open in new window

0
 
RickEpnetConnect With a Mentor Commented:
Try doing the formatting in the SQL Select statement. Which SQL are you using?

http://articles.techrepublic.com.com/5100-10878_11-5803705.html
0
 
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.

0
 
jfreeman2010Author Commented:
Thank you both of your help!!
0
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.