YUI DataTable and Non-US Currency Formats

Recently I have been adding in localized currency formatting to the echotools platform. In most cases I can use the Zend Framework, Zend_Currency to handle most of the heavy lifting. However, we are starting to use the YUI DataTable more and more often, and one such page had me scratching my head trying to figure out how to display a non-US currency in a sortable column.

You see when the columns are not sortable, we can easily treat the column like it is a string, and simply pass in the value with say the British Pound (GBP) symbol or the Euro symbol. But as soon as you want to sort on this column you run into issues. If you set it to a string, then 14.95 comes before 2.50, and that's no good.

If you have ever setup a DataTable, then you probably know that can provide a formatter for the table column, which we had set to currency. When that is the case, YUI defaults to the US Dollar (USD) format. Getting it to show GBP or Euro takes a little work. After a bit of digging around I found that you can modify the currency options as part of your table configuration. Below is an example:

For more details on YUI DataTable options, follow this link to Yahoo's developer network: http://developer.yahoo.com/yui/docs/YAHOO.widget.DataTable.html#config_currencyOptions

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
BlogCFC was created by Raymond Camden. This blog is running version 5.8.001.