[CLOSED] Show Image Component Dynamically

  1. #1

    [CLOSED] Show Image Component Dynamically

    Hi,

    I have need to show a list of record with a image in first position.
    My code is similar to this:

    <ext:GridPanel runat="server" ID="GridPanelRisultato" MarginSpec="2 0 0 0" Flex="1" Border="true">
                <Store>
                    <ext:Store runat="server" ID="StoreRisultato">
                        <Model>
                            <ext:Model runat="server">
                                <Fields>
                                    <ext:ModelField Name="CodiceTipoUtente" Type="String" />
                                    <ext:ModelField Name="CodiceUtente" Type="String" />
                                    <ext:ModelField Name="Cognome" Type="String" />
                                    <ext:ModelField Name="Nome" Type="String" />
                                    <ext:ModelField Name="RagioneSociale" Type="String" />
                                    <ext:ModelField Name="Stato" Type="String" />
                                </Fields>
                            </ext:Model>
                        </Model>
                    </ext:Store>
                </Store>
                <ColumnModel runat="server" EnableColumnHide="False">
                    <Columns>
                        <ext:ComponentColumn runat="server" DataIndex="CodiceTipoUtente" Width="22">
                            <Component>
                                <ext:Image runat="server" Height="20" ImageUrl ="~/Immagini/Cliente.png" />
                            </Component>
                        </ext:ComponentColumn>
                        <ext:Column runat="server" Text="CodiceUtente" DataIndex="CodiceUtente" Width="100"/>
                        <ext:Column runat="server" Text="Cognome" DataIndex="Cognome" Width="100"/>
                        <ext:Column runat="server" Text="Nome" DataIndex="Nome" Width="100"/>
                        <ext:Column runat="server" Text="RagioneSociale" DataIndex="RagioneSociale" Width="100"/>
                        <ext:Column runat="server" Text="Stato" DataIndex="Stato" Width="100"/>
                    </Columns>
                </ColumnModel>
                <Plugins>
                    <ext:FilterHeader runat="server" />
                </Plugins>
            </ext:GridPanel>
    In the code, the line:

    <ext:Image runat="server" Height="20" ImageUrl ="~/Immagini/Cliente.png" />
    show a static Image.... always Cliente.png

    I need to use a dynamic reference to Image, like:

    <ext:Image runat="server" Height="20" ImageUrl ="~/Immagini/{CodiceTipoUtente}.png" />
    Can you help me?

    Tnx
    Last edited by Daniil; Dec 11, 2014 at 7:40 AM. Reason: [CLOSED]
  2. #2
    Hi @Mario,

    Please use a ComponentColumn's BeforeBind like this.

    Example
    <ext:ComponentColumn runat="server" DataIndex="image">
        <Component>
            <ext:Image runat="server" />
        </Component>
        <Listeners>
            <BeforeBind Handler="e.config[0].imageUrl = Ext.net.ResourceMgr.resolveUrl(Ext.String.format('~/Images/{0}.png', e.record.data.image));" />
        </Listeners>
    </ext:ComponentColumn>
  3. #3
    TNX Daniil, It Works!

    Another question:
    How do I add dynamic text (bound to record data) to the right of the image in the same column?

    :)
  4. #4
    You could add a Label. For that you might need to wrap both - Image and Label - in a Container with an HBoxLayout to position them horizontally.
  5. #5
    OK Danill,
    but if I change the code, transforming this:

    <ext:ComponentColumn runat="server" DataIndex="image">
        <Component>
            <ext:Image runat="server" />
        </Component>
        <Listeners>
            <BeforeBind Handler="e.config[0].imageUrl = Ext.net.ResourceMgr.resolveUrl(Ext.String.format('~/Images/{0}.png', e.record.data.image));" />
        </Listeners>
    </ext:ComponentColumn>
    in this:

    <ext:ComponentColumn runat="server" DataIndex="image">
        <Component>
            <ext:Container runat="server" Layout="HBoxLayout" >
                <Items>
                    <ext:Image runat="server" ID="ImageCodiceUtente" Height="20"/>
                    <ext:Label runat="server" ID="LabelCodiceUtente"/>
                </Items>
            </ext:Container>
        </Component>
        <Listeners>
            <BeforeBind Handler="e.config[0].imageUrl = Ext.net.ResourceMgr.resolveUrl(Ext.String.format('~/Images/{0}.png', e.record.data.image));" />
        </Listeners>
    </ext:ComponentColumn>
    the code:

    <BeforeBind Handler="e.config[0].imageUrl = Ext.net.ResourceMgr.resolveUrl(Ext.String.format('~/Images/{0}.png', e.record.data.image));" />
    no longer works !
    And the text property of the new Label "LabelCodiceUtente" not work,

    Can you make an example for resolve this case?

    Tnx
  6. #6
    e.config[0]
    is now the Container, not the Image control.

    Hope this information helps.

    By the way, we would also recommend you to consider using a regular Column with a custom Renderer.
    Last edited by Daniil; Dec 01, 2014 at 8:50 AM.
  7. #7
    I prefer to use the method with the container object, because if I use a script HTML to render the cell content, its content is not centered vertically.

    Danill, can you please tell me how I can set the values of ImageUrl and Text in the two objects in container?

    tnx
  8. #8
    So, "e.config[0]" is the Container. I would expect there should be the "items" property. I would try this first:
    e.config[0].items
    You can debug/explorer it using any tool that you like. I generally prefer the Visual Studio JavaScript debugger.

Similar Threads

  1. Replies: 2
    Last Post: Sep 13, 2013, 7:49 AM
  2. [CLOSED] ext:Image - How I can show a menu when click in ext:Image?
    By supera in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: May 10, 2012, 8:56 PM
  3. [CLOSED] Component image support rotate?
    By stoque in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Jan 16, 2012, 11:00 AM
  4. [CLOSED] Image component
    By stoque in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Nov 28, 2011, 10:00 PM
  5. [CLOSED] Dinamically hide/show DesktopShortcut
    By bakardi in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: May 25, 2011, 2:49 PM

Tags for this Thread

Posting Permissions