TemplateColumn creating issue on Grid updating.

  1. #1

    TemplateColumn creating issue on Grid updating.

    I have next situation.

    1. OnInit create a Grid (with Column model).
    2. On DirectMethid (I did not change column model)
    3. Grid.AddTo(Grig.Parent)
    All OK.

    1. OnInit create a Grid (with Column model).
    2. On DirectMethid (I've changed column model)
    3. Grid.AddTo(Grig.Parent)

    Json responce:
    ....
    this.ctl00_idb27fbcc07e9e4ef69f0eb3c2c5bd7f74=new Ext.net.XTemplate()
    after new Ext.net.XTemplate() there is no ";", and I got JS exception.

    I mean on Grid.AddTo(Grid.Parent), I've got

    Json response.
    Ext.net.ResourceMgr.destroyCmp("MyGrid");
    new Ext.net.GridPanel (..  this.ctl00_idb27fbcc07e9e4ef69f0eb3c2c5bd7f74=new Ext.net.XTemplate() ..)
    this.ctl00_idb27fbcc07e9e4ef69f0eb3c2c5bd7f74=new Ext.net.XTemplate()this.MyGrid_PagingToolbar.pageSize=10;
    there absent ; (Semicolon) after XTemplate()
    Could it be fixed?
    I've got this error only if use TemplateColumn and dynamically change ColumnModel for my grid.

    And where can I get Sources for 1.4 version?
    Last edited by swed; Jun 18, 2012 at 2:46 PM.
  2. #2
    Solution:
    gridPanel.ColumnModel.Columns.Clear();
    foreach (XTemplate xTemplate in gridPanel.Controls.OfType<XTemplate>())
    {
        gridPanel.Controls.Remove(xTemplate);
    }
    This happens because XTemplate has Parent Controls not ColumnModel, but GridPanel.
    Also if you define ID for ColumnTemplate
     ColumnTemplate.Template.ID = "Blablabla";
    you will get error when will try to re-add ColumnTemplate, even if you clear columns of ColumnModel.
  3. #3
    Hi,

    If you change just ColumnModel, I would recommend to call just
    GridPanel.Reconfigure();
    instead of
    GridPanel.AddTo(...);
    Does it work for you?

    Quote Originally Posted by swed View Post
    And where can I get Sources for 1.4 version?
    Here you are.
    https://github.com/extnet/Ext.NET.Community/tree/v1
  4. #4
    Grid.Reconfigure()
    Does Actually only reconfiguration of existing control.
    But I also have custom toolbar with buttons for my Grid.

    I'm using Grid in mixed Data loading mode.
    When I've got page loaded I bind data from DataSource, but for Paging ans Sorting I use WCF Web Service.

    Changing of pageSize dynamically on AsyncPostback (DirectMethod) trigger
    Call("pageSize");
    Call("dataLoad");
    That is worst scenario If I would Destroy and Create Grid after AsyncPostback (DirectMethod).

    I've resolve this situation by setting of paging tool bar visibility, this hard-code avoid of creating ScriptProxy for paging toolbar control.
    pagingToolbar.Visible = false;
    pagingToolbar.PageSize = settings.PageSizel
    pagingToolbar.Visible = true;
    So, Re-configuring is not actually a solution for me.
    I will appreciate any information about how could I re-create control on the page without hard-coding of tricks to get
    control.Render(control.Parent.ClientID, RenderMode.RenderTo);
    works fine for me. As I understand from "Render" method name, it should Destroy and Create control, and it does, but with small unwanted stuffs for me.

    Actually I'm using custom manager to resolve which controls would be updated on the page.
    So, I know nothing about what control I have and, don\t what to hard code comparing of a type to use "recofigure".
    And don't know is this control already presents on the page or it had
    Visible=false
    before.

    Is any way to Destroy and Create control without re-configuring and re-loading?
    Last edited by swed; Jun 19, 2012 at 6:33 AM.
  5. #5
    Any ideas?
    Please, write the answer, whatever it was.
  6. #6
    Apologize for the delay, very busy here. I will review in 1-2 days.
  7. #7
    According to the details you have provided re-rendering the GridPanel appears to be the best approach for you.

    I would place the GridPanel into some Ext.NET container, for example, <ext:Container> and call:
    this.GridPanel1.Render();
    without any parameters.

    I am able to reproduce the initial issue with the example below. I would consider it a bug. I think the
    .Columns.Clear()
    should automatically remove the XTemplate control. We will investigate. Your workaround looks good for now.

    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[] { "test1", "test2", "test3" },
                    new object[] { "test4", "test5", "test6" },
                    new object[] { "test7", "test8", "test9" }
                };
                store.DataBind();
            }
        }
    
        protected void Rerender(object sender, DirectEventArgs e)
        {
            this.GridPanel1.ColumnModel.Columns.Clear();       
            this.GridPanel1.Render();
        }
    </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>
        <ext:ResourceManager runat="server" />
    
        <ext:Container runat="server">
            <Items>
                <ext:GridPanel ID="GridPanel1" runat="server" AutoHeight="true">
                    <Store>
                        <ext:Store runat="server">
                            <Reader>
                                <ext:ArrayReader>
                                    <Fields>
                                        <ext:RecordField Name="test1" />
                                        <ext:RecordField Name="test2" />
                                        <ext:RecordField Name="test3" />
                                    </Fields>
                                </ext:ArrayReader>
                            </Reader>
                        </ext:Store>
                    </Store>
                    <ColumnModel runat="server">
                        <Columns>
                            <ext:Column Header="Test1" DataIndex="test1" />
                            <ext:Column Header="Test2" DataIndex="test2" />
                            <ext:TemplateColumn Header="TemplateColumn" DataIndex="test3">
                                <Template runat="server">
                                    <Html>
                                        <b>{test3}</b>
                                    </Html>
                                </Template>
                            </ext:TemplateColumn>
                        </Columns>
                    </ColumnModel>
                </ext:GridPanel>
            </Items>
        </ext:Container>
            
        <ext:Button runat="server" Text="Rerender the GridPanel" OnDirectClick="Rerender" />
    </body>
    </html>
    Also I don't think you need that:
    pagingToolbar.Visible = false;
    pagingToolbar.PageSize = settings.PageSize;
    pagingToolbar.Visible = true;
    The Render method calling should totally recreate the GridPanel BottomBar as well.

    Is any way to Destroy and Create control without re-configuring and re-loading?
    Do you mean reloading the Store? I don't think it's possible. Rerendering totally destroys the previous instance with all data. You could cache that data if you wish and manually load into the Store after re-rendering.
  8. #8
    Quote Originally Posted by Daniil View Post
    I am able to reproduce the initial issue with the example below. I would consider it a bug. I think the
    .Columns.Clear()
    should automatically remove the XTemplate control. We will investigate. Your workaround looks good for now.
    We had to leave that in v1. Please use:
    for (int i = this.GridPanel1.ColumnModel.Columns.Count - 1; i > -1 ; i--)
    {
        this.GridPanel1.ColumnModel.Columns.RemoveAt(i);
    }
    instead of
    this.GridPanel1.ColumnModel.Columns.Clear();
    to ensure all columns will be correctly destroyed.

    And you can use
    this.GridPanel1.ColumnModel.Columns.Clear();
    in Ext.NET v2 without any restrictions.

    Anyways, big thanks for the report.

Similar Threads

  1. How to set Grid Panel's css when updating
    By alleusai in forum 2.x Help
    Replies: 0
    Last Post: Jul 03, 2012, 2:39 PM
  2. Replies: 0
    Last Post: Mar 27, 2012, 10:01 AM
  3. Issue when creating Menuitems dynamically
    By kondareddy1984 in forum 1.x Help
    Replies: 1
    Last Post: Mar 11, 2011, 5:47 PM
  4. Problem with updating grid panel
    By Nagaraj K Hebbar in forum 1.x Help
    Replies: 0
    Last Post: May 09, 2009, 12:52 PM
  5. Example: Updating a Grid Cell programatically
    By Juls in forum Examples and Extras
    Replies: 1
    Last Post: Apr 08, 2009, 1:44 PM

Tags for this Thread

Posting Permissions