UPDATE:
EuroMoney format is now included with Ext.Net Revision #3327
---
Today, I needed the currency Euro/EUR (€) within some Grids. So I search the Forums, and Tada! Found this nice example from Ext.Net Support Member Daniil. I just did some more tests and made some minor code style changes.
ASPX (Codebehind):
protected void Page_Load(object sender, EventArgs e) { if (!X.IsAjaxRequest) { Store store = this.GPanel.GetStore(); store.DataSource = new object[] { new object[] {200000.12, 200000.12}, new object[] {-1123.42, -1123.42}, new object[] {3.42, 3.42}, new object[] {-0.42, -0.42}, new object[] {-42.456, -42.456}, new object[] {10000042.456, 10000042.456}, new object[] {-99000042.456, -99000042.456}, new object[] {99000042.451, 99000042.451}, new object[] {32.429, 32.429}, new object[] {15300.99, 15300.99}, new object[] {-15300.99, -15300.99}, new object[] {-5199.98, -5199.98}, new object[] {5199.98, 5199.98} }; store.DataBind(); } }ASPX:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title>EURO Currency Renderer</title> </head> <body> <ext:ResourceManager ID="resManager" runat="server" Theme="Gray" RemoveViewState="true" /> <form runat="server" id="app"> <ext:GridPanel ID="GPanel" runat="server" AutoHeight="true"> <Store> <ext:Store ID="Store" runat="server"> <Reader> <ext:ArrayReader> <Fields> <ext:RecordField Name="EUR" /> <ext:RecordField Name="USD" /> </Fields> </ext:ArrayReader> </Reader> </ext:Store> </Store> <ColumnModel ID="ColumnModel1" runat="server"> <Columns> <ext:Column Header="EUR" DataIndex="EUR"> <Renderer Handler="return EuroMoney(value);" /> </ext:Column> <ext:Column Header="USD" DataIndex="USD"> <Renderer Format="UsMoney" /> </ext:Column> </Columns> </ColumnModel> </ext:GridPanel> <ext:XScript runat="server" ID="scripts"> <script type="text/javascript"> // EURO Currency Renderer var EuroMoney = function (v) { v = (Math.round((v - 0) * 100)) / 100; v = (v == Math.floor(v)) ? v + ".00" : ((v * 10 == Math.floor(v * 10)) ? v + "0" : v); v = String(v); var m = v.split('.'); var whole = m[0]; var sub = m[1] ? ',' + m[1] : ',00'; var r = /(\d+)(\d{3})/; while (r.test(whole)) { whole = whole.replace(r, '$1' + '.' + '$2'); } v = whole + sub; return v + " €"; } </script> </ext:XScript> </form> </body> </html>
Keine Kommentare:
Kommentar veröffentlichen