Problem with dynamic grids and record parameter in column renderer

  1. #1

    Problem with dynamic grids and record parameter in column renderer


    I am using a grid with dynamic columns and a custom column render. If the column names change with each render, the "record" parameter received by the renderer has all the fields the grid has had instead of only the current ones. Here is an example:

    <%@ Page Language="C#" %>
    <%@ Import Namespace="System.Data" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    <ext:ResourcePlaceHolder ID="ResourcePlaceHolder1" runat="server" Mode="ScriptFiles" />
    <script type="text/javascript"> = () {
        function MyRenderer(value, metadata, record, rowIndex, colIndex, store) {
            return record.fields.length;
    <script runat="server">
        Random rnd = new Random();
        public void Prepare_Click(object sender, DirectEventArgs e)
        private void PrepareGrid(GridPanel grid)
            // Add columns to grid.
            var columns = new string[] { "Text1_" + rnd.Next(9), "Num1_" + rnd.Next(9), "Text2_" + rnd.Next(9), "Num2_" + rnd.Next(9), "Comments" };
            foreach (string col in columns)
                Column newCol = new Column { Header = col, DataIndex = col, Width = 120, MenuDisabled = true, Sortable = false };
            // Add records to store reader.        
            RecordField newRecord1 = new RecordField(columns[0], RecordFieldType.String);
            RecordField newRecord2 = new RecordField(columns[1], RecordFieldType.Int);
            RecordField newRecord3 = new RecordField(columns[2], RecordFieldType.String);
            RecordField newRecord4 = new RecordField(columns[3], RecordFieldType.Int);
            // Create data table
            DataTable data = new DataTable();
            data.Columns.Add("Date", typeof(DateTime));
            data.Columns.Add(columns[0], typeof(string));
            data.Columns.Add(columns[1], typeof(int));
            data.Columns.Add(columns[2], typeof(string));
            data.Columns.Add(columns[3], typeof(int));
            data.Columns.Add("Comments", typeof(string));
            data.Rows.Add(DateTime.Now, "Line 1 " + rnd.Next(9), 10, "Some text " + rnd.Next(9), 20, "Correct");
            data.Rows.Add(DateTime.Now.AddDays(1).AddHours(1), "Line 2 " + rnd.Next(9), 15, "More text " + rnd.Next(9), 25, "Wrong");
            this.strDemo.DataSource = data;
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    <html xmlns="">
    <head id="Head1" runat="server">
        <title>Dynamic Grid - Record Fields Problem</title>
        <form id="Form1" runat="server">
            <ext:ResourceManager ID="ResourceManager1" runat="server" />
            <ext:Store ID="strDemo" runat="server">
                    <ext:JsonReader IDProperty="Date">
                            <ext:RecordField Name="Date" Type="Date" />
                            <ext:RecordField Name="Comments" Type="String" />
            <ext:Viewport ID="Viewport1" runat="server" Layout="border">
                    <ext:Panel runat="server" Region="West" Width="100">
                            <ext:Button runat="server" ID="btnPrepare" Text="Load">
                                    <Click OnEvent="Prepare_Click" />
                    <ext:Panel runat="server" Region="Center">
                            <ext:GridPanel ID="myGrid" runat="server" StoreID="strDemo" AutoHeight="true" EnableColumnMove="false" EnableColumnResize="false">
                                <ColumnModel ID="ColumnModel1" runat="server">
                                        <ext:Column Header="Field Count">
                                            <Renderer Fn="MyRenderer" />
                                        <ext:DateColumn Header="Day" DataIndex="Date" Format="MM/dd/yyyy" MenuDisabled="true" Sortable="false" />
                                        <ext:DateColumn Header="Time" DataIndex="Date" Format="HH:mm:ss" MenuDisabled="true" Sortable="false" />
                                    <ext:GridView />
    Each time you press Load, new random column names are rendered and new data is loaded, but in record.fields (as well as store.fields) all previous dynamic fields are still present. This is shown in the "Field Count" column, which has the renderer. The main problem is then that the colIndex parameter, which corresponds to the actual column model, doesn't match with this list of fields and I can't know what column it's actually rendering.

    Summarizing, the datasource table, the store and the column model all have the appropriate columns, but the fields in the record and the store parameters sent to the renderer keep the old ones.

    Am I missing clearing something? I couldn't find anything wrong from the code behind.
    Is there a way to prevent this? It happens with all 1.x versions I have tested.

    Thanks and regards,

    Last edited by ALobpreis; May 28, 2014 at 12:42 PM.
  2. #2
    Could this issue be reproduced? Or is it due to some error in my code? For the moment what I did was "convert" with some loops the received colIndex to the one that corresponds to the record fields received as parameter.

    Thanks and regards,

  3. #3
    I still have problems with this. I only get the colIndex and have no way to know which column is actually being rendered; the index doesn't belong to the field list.

Similar Threads

  1. [CLOSED] Custom parameter in grid column Renderer
    By alscg in forum 2.x Premium Help
    Replies: 6
    Last Post: Dec 16, 2013, 3:01 AM
  2. Replies: 4
    Last Post: Jun 05, 2013, 2:40 PM
  3. Replies: 1
    Last Post: Mar 12, 2013, 10:35 AM
  4. [CLOSED] GridPanel: Problem with Dynamic Column
    By nhg_itd in forum 1.x Premium Help
    Replies: 7
    Last Post: Oct 19, 2011, 9:47 AM
  5. Two Grids - submit additional parameter [0.82]
    By roszman in forum 1.x Help
    Replies: 2
    Last Post: Jun 24, 2010, 7:11 AM

Tags for this Thread

Posting Permissions