[CLOSED] Euro in grid

  1. #1

    [CLOSED] Euro in grid

    Hi,

    How to render a proper euro column is the question.

    I have:

     <ext:GridPanel ID="gpPrices" runat="server" Height="300" StoreID="storePices" AutoWidth="true">
        <ColumnModel ID="ColumnModel1" runat="server">
            <Columns>
                <ext:NumberColumn DataIndex="Id" Header="Id" Hidden="true" Format="" />
                <ext:NumberColumn DataIndex="Name" Header="Kaartsoort" Align="Right" />
                <ext:NumberColumn DataIndex="Price1" Header="Price1" Align="Right" Format="&euro; 0.00"/>                  
                <ext:Column DataIndex="Price2" Header="Price2" Align="Right" >
                    <Renderer Format="UsMoney"/>
                </ext:Column>
            </Columns>
        </ColumnModel>
    </ext:GridPanel>
    As you can see the price 2 column has the usMoney and Price1 has a formatting set. Only the decimal seperator is stil a dot while it should be a comma.


    In here a renderer solution is discussed. Is this still the way to go?


    Thanks
    Last edited by Daniil; Sep 29, 2010 at 6:45 PM. Reason: [CLOSED]
  2. #2
    Hi Edward,

    Please look at the example.

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                Store store = this.GridPanel1.GetStore();
                store.DataSource = new object[] { 
                                             new object[] {200000.12, 200000.12},
                                             new object[] {-1123.42, -1123.42}
                                    };
                store.DataBind();
            }
        }
    </script>
    
    <!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 runat="server">
        <title>Ext.Net Example</title>
    
        <script type="text/javascript">
            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 ps = v.split('.'),
                    whole = ps[0],
                    sub = ps[1] ? ',' + ps[1] : ',00',
                    r = /(\d+)(\d{3})/;
                while (r.test(whole)) {
                    whole = whole.replace(r, '$1' + '.' + '$2');
                }
                v = whole + sub;
    
                return v + " ?";
            }
        </script>
    </head>
    <body>
        <form runat="server">
        <ext:ResourceManager runat="server" />
        <ext:GridPanel ID="GridPanel1" runat="server" AutoHeight="true">
            <Store>
                <ext:Store runat="server">
                    <Reader>
                        <ext:ArrayReader>
                            <Fields>
                                <ext:RecordField Name="euro" />
                                <ext:RecordField Name="usd" />
                            </Fields>
                        </ext:ArrayReader>
                    </Reader>
                </ext:Store>
            </Store>
            <ColumnModel runat="server">
                <Columns>
                    <ext:Column Header="euro" DataIndex="euro">
                        <Renderer Handler="return euroMoney(value);"/>
                    </ext:Column>
                    <ext:Column Header="usd" DataIndex="usd">
                        <Renderer Format="UsMoney" />
                    </ext:Column>
                </Columns>
            </ColumnModel>
        </ext:GridPanel>
        </form>
    </body>
    </html>
  3. #3
    That could work, it looks like the code from http://www.sencha.com/forum/showthre...r-than-usMoney that thread is interesting because there is code which also deals with differences within the euro zone.


    This one is also nice: http://www.sencha.com/forum/showthre...t.formatNumber

    For now I'm going with a simple replace of the decimal seperator.
  4. #4
    Yes, there is a lot of formats and a lot of ways to format our data.
  5. #5
    EuroMoney format was added to the toolkit's core (Revision #3327)

    Request ticket:
    https://extnet.lighthouseapp.com/pro...at#ticket-53-2

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                Store store = this.GridPanel1.GetStore();
                store.DataSource = new object[] 
                {
                    new object[] { 200000.12 },
                    new object[] { -1123.42 },
                    new object[] { 3.42 },
                    new object[] { -0.42 },
                    new object[] { -42.456 },
                    new object[] { 10000042.456 },
                    new object[] { -99000042.456 },
                    new object[] { 99000042.451 },
                    new object[] { 32.429 },                          
                    new object[] { 15300.99 },
                    new object[] { -15300.99 },
                    new object[] { -5199.98 },
                    new object[] { 5199.98 }
                };
                store.DataBind();
            }
        }
    </script>
    
    <!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 runat="server">
        <title>Ext.Net Example</title>
    </head>
    <body>
        <form runat="server">
        <ext:ResourceManager runat="server" />
        <ext:GridPanel ID="GridPanel1" runat="server" AutoHeight="true">
            <Store>
                <ext:Store runat="server">
                    <Reader>
                        <ext:ArrayReader>
                            <Fields>
                                <ext:RecordField Name="money" />
                            </Fields>
                        </ext:ArrayReader>
                    </Reader>
                </ext:Store>
            </Store>
            <ColumnModel runat="server">
                <Columns>
                    <ext:Column Header="euro" DataIndex="money">
                        <Renderer Format="EuroMoney" />
                    </ext:Column>
                    <ext:Column Header="usd" DataIndex="money">
                        <Renderer Format="UsMoney" />
                    </ext:Column>
                </Columns>
            </ColumnModel>
        </ext:GridPanel>
        </form>
    </body>
    </html>
  6. #6
    Thanks. Nice one! Makes things even simpler.

Similar Threads

  1. Replies: 5
    Last Post: Dec 26, 2011, 5:39 AM
  2. [CLOSED] How to update all updated grid info in Editable Grid?
    By rnachman in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Dec 06, 2011, 3:56 PM
  3. [CLOSED] Hidden Change and Grid Filters are not working after Grid Reconfigure
    By speedstepmem3 in forum 1.x Legacy Premium Help
    Replies: 15
    Last Post: Oct 16, 2011, 1:12 PM
  4. Replies: 16
    Last Post: Feb 23, 2011, 10:03 AM
  5. currency euro
    By maxdiable in forum 1.x Help
    Replies: 1
    Last Post: Jul 28, 2009, 10:53 AM

Tags for this Thread

Posting Permissions