[CLOSED] Renderer on a TemplateColumn: not working

  1. #1

    [CLOSED] Renderer on a TemplateColumn: not working

    Hi,
    i noticed that using a renderer on a TemplateColumn doesn't work. How do i solve this issue?

    In the example below i would like to have the same background-color in both the Data and Number columns.

    <%@ Page Language="C#" %>
     
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     
    <script runat="server">
        public class DataRecord
        {
            public int Id { get; set; }
            public string Data { get; set; }
            public float Number { get; set; }
            public bool IsOk { get; set; }
        }
     
        protected void Page_Load(object sender, EventArgs e)
        {
            this.DataStore.DataSource = this.GetData();
            this.DataStore.DataBind();
        }
     
        private List<DataRecord> GetData()
        {
            return new List<DataRecord>
            {
                new DataRecord { Id = 1, Data = "Data1", Number = 10, IsOk = true},
                new DataRecord { Id = 2, Data = "Data2", Number = 11, IsOk = false },
                new DataRecord { Id = 3, Data = "Data3", Number = 12, IsOk = true },
                new DataRecord { Id = 4, Data = "Data4", Number = 13, IsOk = false },
            };
        }
    </script>
     
     
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>Sample</title>
    
        <script type="text/javascript">
    
            function render(value, metadata, record, rowIndex, colIndex, store) {
                if (record.get("IsOk")) {
                    metadata.style += "background-color: #FFFAC8;";
                }
                return value;
            }
        </script>
     
    </head>
    <body>
    
        <ext:ResourceManager ID="ResourceManager1" runat="server" />
             
        <ext:Store runat="server" ID="DataStore">
            <Reader>
                <ext:JsonReader IDProperty="Id">
                    <Fields>
                        <ext:RecordField Name="Id" Type="Int" />
                        <ext:RecordField Name="Data" Type="String"/>
                        <ext:RecordField Name="Number" Type="Float"/>
                        <ext:RecordField Name="IsOk" Type="Boolean"/>
                    </Fields>
                </ext:JsonReader>
            </Reader>
        </ext:Store>
     
        <ext:Viewport runat="server" ID="Viewport" Layout="Fit">
            <Items>
                <ext:GridPanel
                    runat="server"
                    ID="GridPanel"
                    StoreID="DataStore" 
                    Title="Table"
                    Icon="Table"
                    Frame="true">
                    <ColumnModel ID="ColumnModel" runat="server">
                        <Columns>
                            <ext:Column Header="ID" DataIndex="Id" />
                            <ext:TemplateColumn Header="Data" DataIndex="Data">
                                <Renderer Fn="render" />
                                <Template ID="Template" runat="server">
                                    <Html>
                                        <b>{Data}</b>
                                    </Html>
                                </Template>
                            </ext:TemplateColumn>
                            <ext:Column Header="Number" DataIndex="Number" >
                                <Renderer Fn="render"/>
                            </ext:Column>
                        </Columns>
                    </ColumnModel>
                    <SelectionModel>
                        <ext:RowSelectionModel ID="RowSelectionModel" runat="server" />
                    </SelectionModel>
                    <LoadMask ShowMask="true" />
                </ext:GridPanel>
            </Items>
        </ext:Viewport>
    </body>
    </html>
    Last edited by Daniil; Oct 19, 2010 at 1:37 PM. Reason: [CLOSED]
  2. #2
    Hi,

    A TemplateColumn doesn't support a custom renderer. It uses Template to render a value.

    In your case I would suggest you to use a common Column with a custom Renderer:

    Example
    var rendererData = function (value, metadata, record, rowIndex, colIndex, store) {
        metadata.style += "font-weight: bold;"
        if (record.get("IsOk")) {
            metadata.style += "background-color: #FFFAC8;";
        }
        return value;
    }
    
    ...
    
    <ext:Column Header="Data" DataIndex="Data">
        <Renderer Fn="rendererData " />
    </ext:Column>
  3. #3
    Quote Originally Posted by Daniil View Post
    A TemplateColumn doesn't support a custom renderer.
    Thanks, that's what i need to know ;)
    I will go as you suggested.
  4. #4

    Template Colums

    Hi Daniil,
    How can I add new Template columns in my gridpanel ?
    I dont have column in my store. I want to add new column to have user input.
    I have tried <ext:TemplateColumn> </ext:TemplateColumn> but It does not show up in gridpanel. what should be the dataIndex for the template column ?

    Can you please guide.

    Thanks
  5. #5
    @QualityCode - Please start a new thread. This thread was marked as [CLOSED] a while ago. Feel free to cross-link between threads if you feel they are related.
    Geoffrey McGill
    Founder
  6. #6
    Thanks for useful suggestion :)

Similar Threads

  1. Replies: 7
    Last Post: Jun 29, 2012, 1:22 PM
  2. Adding Dropdown box to TemplateColumn of GridPanel
    By Mrityunjay in forum 2.x Help
    Replies: 0
    Last Post: Jun 19, 2012, 9:41 AM
  3. [CLOSED] TemplateColumn Click Not Registering
    By peter.campbell in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Nov 14, 2011, 12:24 PM
  4. [CLOSED] Embedding server tags in TemplateColumn
    By pj_martins in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Oct 30, 2011, 1:39 PM
  5. [CLOSED] Problem with TemplateColumn
    By xeo4.it in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Nov 30, 2010, 10:19 AM

Tags for this Thread

Posting Permissions