Problem with dynamic column header grouping

Page 3 of 3 FirstFirst 123
  1. #21
    As always, your suggestion really helped me but a new problem arose.

    Now the grid is rendering properly but I get this a javascript error in this line of a WebResource.axd because selModel is null.
    doSelection:function(){var data=this.selModel.selectedData
    Our grid has a CellSelectionModel with a listener working properly.

    And if I try to re-render the grid with new data, it disappears. In this case, the error is that config[a] is undefined.
    getColumnId:function(a){return this.config[a].id}
    However, this may be due to the previous error though, so first comes first. I will do some more tests and post an example if needed.

    Thank you very much. I hope you are not running out of patience. :)
    Last edited by ALobpreis; May 08, 2014 at 4:13 PM.
  2. #22
    Yes, a test case to reproduce is appreciated:)

    I hope you are not running out of patience. :)
    No worries since you are good to provide us with samples to reproduce:)
  3. #23
    Here it is:

    <%@ Page Language="C#" %>
    <%@ Import Namespace="System.Data" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <script runat="server">
    
        Random rndGenerator = new Random();
        [DirectMethod]
        public void OnClick(object sender, DirectEventArgs e)
        {
            PrepareGrid(myGrid, 1);
        }
    
        [DirectMethod]
        public void OnClick2(object sender, DirectEventArgs e)
        {
            PrepareGrid(myGrid, 2);
        }
    
        [DirectMethod]
        public void LoadOnClick(object sender, DirectEventArgs e)
        {
            DataTable data = new DataTable();
            data.Columns.Add("Date", typeof(DateTime));
            data.Columns.Add("Text1", typeof(string));
            data.Columns.Add("Num1", typeof(int));
            data.Columns.Add("Text2", typeof(string));
            data.Columns.Add("Num2", typeof(int));
            data.Columns.Add("Comments", typeof(string));
    
            data.Rows.Add(DateTime.Now, "Line 1", 10, "Random: " + rndGenerator.Next(100).ToString(), 20, "Correct");
            data.Rows.Add(DateTime.Now.AddDays(1).AddHours(1), "Line 2", 15, "Another random: " + rndGenerator.Next(100).ToString(), 25, "Wrong");
    
            this.strDemo.DataSource = data;
            this.strDemo.DataBind();
        }
    
        private void PrepareGrid(GridPanel grid, int version)
        {
            var columns = new string[] { "Text1",  "Num1", "Text2", "Num2", "Comments" };
    
            foreach (string col in columns)
            {
                if (version == 2 && col.EndsWith("2"))
                    continue;
    
                Column newCol = new Column { Header = col + version.ToString(" (0)"), DataIndex = col, Width = 120 };
                grid.ColumnModel.Columns.Add(newCol);
            }
    
            var headerGroupRow = new HeaderGroupRow();
            var headerGroups = new[] { new { Header = "Date", Span = 2 }, new { Header = "Group 1", Span = 2 },
                new { Header = "Group 2", Span = 2}, new { Header = "", Span = 1}};
    
            foreach (var header in headerGroups)
            {
                if (version == 2 && header.Header.EndsWith("2"))
                    continue;
    
                headerGroupRow.Columns.Add(new HeaderGroupColumn
                {
                    Header = header.Header,
                    Align = Alignment.Center,
                    ColSpan = header.Span
                });
            }
    
            grid.View.View.HeaderGroupRows.Add(headerGroupRow);
            myGrid.Controls.RemoveAt(0);
            myGrid.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 id="Head1" runat="server">
        <title>Dynamic Grid Column Header Grouping Problem</title>
    </head>
    <body>
        <ext:ResourceManager ID="ResourceManager1" runat="server" />
    
        <ext:Store ID="strDemo" runat="server">
            <Reader>
                <ext:JsonReader>
                    <Fields>
                        <ext:RecordField Name="Date" Type="Date" />
                        <ext:RecordField Name="Text1" Type="String" />
                        <ext:RecordField Name="Num1" Type="Int" />
                        <ext:RecordField Name="Text2" Type="String" />
                        <ext:RecordField Name="Num2" Type="Int" />
                        <ext:RecordField Name="Comments" Type="String" />
                    </Fields>
                </ext:JsonReader>
            </Reader>
        </ext:Store>
    
        <ext:Viewport ID="Viewport1" runat="server" Layout="border">
            <Items>
    
                <ext:Panel runat="server" Region="North" Height="200">
                    <Content>
                        <h1>Dynamic Grid Column Header Grouping Problem</h1>
                        <ext:Label runat="server" Text="North Panel" />
                    </Content>
                </ext:Panel>
    
                <ext:Panel runat="server" Region="West" Width="100">
                    <Items>
                        <ext:Button runat="server" ID="btnPrepare" Text="Prepare Grid">
                            <DirectEvents>
                                <Click OnEvent="OnClick" />
                            </DirectEvents>
                        </ext:Button>
                        <ext:Button runat="server" ID="btnLoad" Text="Load data">
                            <DirectEvents>
                                <Click OnEvent="LoadOnClick" />
                            </DirectEvents>
                        </ext:Button>
                        <ext:Button runat="server" ID="btnPrepare2" Text="Prepare Small">
                            <DirectEvents>
                                <Click OnEvent="OnClick2" />
                            </DirectEvents>
                        </ext:Button>
                    </Items>
                </ext:Panel>
    
                <ext:Panel runat="server" Region="Center">
                    <Items>
                        <ext:GridPanel ID="myGrid" runat="server" StoreID="strDemo" AutoHeight="true">
                            <ColumnModel ID="ColumnModel1" runat="server">
                                <Columns>
                                    <ext:DateColumn Header="Day" DataIndex="Date" Format="MM/dd/yyyy" />
                                    <ext:DateColumn Header="Time" DataIndex="Date" Format="HH:mm" />
                                </Columns>
                            </ColumnModel>
                            <View>
                                <ext:GroupingView>
                                    <HeaderGroupRows>
                                    </HeaderGroupRows>
                                </ext:GroupingView>
                            </View>
                        </ext:GridPanel>
                    </Items>
                </ext:Panel>
    
            </Items>
        </ext:Viewport>
    
    </body>
    </html>
    As soon as you do the data load, you get the error. You can see it with the developer toolbar console or when debugging with Visual Studio, for example. If I DataBind first and then render the grid, the error doesn't take place.
    I put another button to perform a second grid layout in order to try to reproduce the other problem I have but it seems to work ok for now. I added some random numbers (like the "version" parameter) just to help notice when the grid is refreshed.

    BTW, what is the exact difference between Content and Items of a Panel? I see that Content is required if I'm using at least one non-Ext control. Here is an explanation I found but am not sure if my conclusion is totally right.

    Thanks and regards,
  4. #24
    It looks a bug as well. Please add this to the page's <head>.
    <ext:ResourcePlaceHolder runat="server" Mode="ScriptFiles" />
        
    <script type="text/javascript">
        Ext.net.GridPanel.prototype.doSelection = Ext.net.GridPanel.prototype.doSelection.createInterceptor(function() {
            this.getSelectionModel();
        });
    </script>
    Quote Originally Posted by ALobpreis View Post
    BTW, what is the exact difference between Content and Items of a Panel? I see that Content is required if I'm using at least one non-Ext control. Here is an explanation I found but am not sure if my conclusion is totally right.
    I don't think that I can add some technical details to what Vladimir is already wrote in the post that you mentioned, but the rule is quite simple: use <Items> whenever possible (yes, for Ext.NET components), if not, use <Content> (yes, for non-Ext.NET components).
  5. #25
    Daniil, you are the man!!! Thank you very very much for all your fast and precise responses. I guess it would have been totally impossible for me to achieve this otherwise.

    Nevertheless, there is one thing that I am still unable to do: configure a click listener for the group header row. If I even set a click listener for the whole grid, it's not working, either this row is dynamic or written in the markup. Right now I have a HeaderClick listener and it only works in the actual column headers.

    And one last small detail: the column headers background gradient is greenish while the group header background is gray. I see they are using a background-image with a different WebResource.axd. Where is this set?

    Click for zoomed screenshot:
    Click image for larger version. 

Name:	Header.png 
Views:	40 
Size:	2.1 KB 
ID:	10821

    Thanks and regards!

    Andrew
    Last edited by ALobpreis; May 12, 2014 at 1:46 PM.
  6. #26
    I think it goes away from the original topic of this thread. Please start a new forum thread for each new question.
  7. #27
    Unfortunately there is another problem related to this topic: the SelectionModel after a DirectEvent is not working. Check this 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" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <ext:ResourcePlaceHolder ID="ResourcePlaceHolder1" runat="server" Mode="ScriptFiles" />
    
    <script type="text/javascript">
        Ext.net.GridPanel.prototype.doSelection = Ext.net.GridPanel.prototype.doSelection.createInterceptor(function () {
            this.getSelectionModel();
        });
    
        function Cell_Listener(record, rowIndex, colIndex) {
            document.getElementById('<%= status.ClientID %>').innerHTML = 'Bottom Grid Listener - Row: ' + rowIndex + ' Col: ' + colIndex;
        }
    </script>
    
    <script runat="server">
    
        Random rndGenerator = new Random();
    
        enum RenderMode
        {
            WithGroupHeaders = 1,
            WithoutGroupHeaders = 2
        };
        
        [DirectMethod]
        public void Prepare_Click(object sender, DirectEventArgs e)
        {
            PrepareGrid(topGrid, RenderMode.WithoutGroupHeaders);
            PrepareGrid(bottomGrid, RenderMode.WithGroupHeaders);
        }
    
        [DirectMethod]
        public void Load_Click(object sender, DirectEventArgs e)
        {
            DataTable data = new DataTable();
            data.Columns.Add("Date", typeof(DateTime));
            data.Columns.Add("Text1", typeof(string));
            data.Columns.Add("Num1", typeof(int));
            data.Columns.Add("Text2", typeof(string));
            data.Columns.Add("Num2", typeof(int));
            data.Columns.Add("Comments", typeof(string));
    
            data.Rows.Add(DateTime.Now, "Line 1", 10, "Random: " + rndGenerator.Next(100).ToString(), 20, "Correct");
            data.Rows.Add(DateTime.Now.AddDays(1).AddHours(1), "Line 2", 15, "Another random: " + rndGenerator.Next(100).ToString(), 25, "Wrong");
    
            this.strDemo.DataSource = data;
            this.strDemo.DataBind();
        }
    
        [DirectMethod]
        public void Cell_Click(object sender, DirectEventArgs e)
        {
            CellSelectionModel csm = sender as CellSelectionModel;
            X.MessageBox.Show(new MessageBoxConfig() { Message = "Row: " + csm.SelectedCell.RowIndex + " Col: " + csm.SelectedCell.ColIndex + " Cell Content: [" + csm.SelectedCell.Value + "]", Buttons = MessageBox.Button.OK, Width = 300 });
        }
    
        private void PrepareGrid(GridPanel grid, RenderMode version)
        {
            var columns = new string[] { "Text1", "Num1", "Text2", "Num2", "Comments" };
    
            foreach (string col in columns)
            {
                Column newCol = new Column { Header = col, DataIndex = col, Width = 120, MenuDisabled = true, Sortable = false };
                grid.ColumnModel.Columns.Add(newCol);
                if (version == RenderMode.WithoutGroupHeaders)
                    grid.AddColumn(newCol);
            }
    
            var headerGroupRow = new HeaderGroupRow();
            var headerGroups = new[] { new { Header = "Date", Span = 2 }, new { Header = "Group 1", Span = 2 },
                new { Header = "Group 2", Span = 2}, new { Header = "", Span = 1}};
    
            foreach (var header in headerGroups)
            {
                headerGroupRow.Columns.Add(new HeaderGroupColumn
                {
                    Header = header.Header,
                    Align = Alignment.Center,
                    ColSpan = header.Span
                });
            }
    
            if (version == RenderMode.WithGroupHeaders)
            {
                grid.View.View.HeaderGroupRows.Add(headerGroupRow);
                grid.Controls.RemoveAt(0);
                grid.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 id="Head1" runat="server">
        <title>Dynamic Grid Column Header Grouping Problem</title>
    </head>
    <body>
        <form id="Form1" runat="server">
            <ext:ResourceManager ID="ResourceManager1" runat="server" />
    
            <ext:Store ID="strDemo" runat="server">
                <Reader>
                    <ext:JsonReader IDProperty="Date">
                        <Fields>
                            <ext:RecordField Name="Date" Type="Date" />
                            <ext:RecordField Name="Text1" Type="String" />
                            <ext:RecordField Name="Num1" Type="Int" />
                            <ext:RecordField Name="Text2" Type="String" />
                            <ext:RecordField Name="Num2" Type="Int" />
                            <ext:RecordField Name="Comments" Type="String" />
                        </Fields>
                    </ext:JsonReader>
                </Reader>
            </ext:Store>
    
            <ext:Viewport ID="Viewport1" runat="server" Layout="border">
                <Items>
    
                    <ext:Panel runat="server" Region="North" Height="200">
                        <Content>
                            <h1>Dynamic Grid Column Header Grouping Problem</h1>
                            <ext:Label runat="server" Text="North Panel" />
                            <ext:GridPanel ID="topGrid" runat="server" StoreID="strDemo" AutoHeight="true">
                                <ColumnModel ID="ColumnModel2" runat="server">
                                    <Columns>
                                        <ext:DateColumn Header="Day" DataIndex="Date" Format="MM/dd/yyyy" MenuDisabled="true" Sortable="false" />
                                        <ext:DateColumn Header="Time" DataIndex="Date" Format="HH:mm" MenuDisabled="true" Sortable="false" />
                                    </Columns>
                                </ColumnModel>
                                <SelectionModel>
                                    <ext:CellSelectionModel ID="CellSelectionModel2" runat="server">
                                        <DirectEvents>
                                            <CellSelect OnEvent="Cell_Click" />
                                        </DirectEvents>
                                    </ext:CellSelectionModel>
                                </SelectionModel>
                                <View>
                                    <ext:GroupingView>
                                        <HeaderGroupRows>
                                        </HeaderGroupRows>
                                    </ext:GroupingView>
                                </View>
                            </ext:GridPanel>
                        </Content>
                    </ext:Panel>
    
                    <ext:Panel runat="server" Region="West" Width="100">
                        <Items>
                            <ext:Button runat="server" ID="btnPrepare" Text="Prepare Grids">
                                <DirectEvents>
                                    <Click OnEvent="Prepare_Click" />
                                </DirectEvents>
                            </ext:Button>
                            <ext:Button runat="server" ID="btnLoad" Text="Load data">
                                <DirectEvents>
                                    <Click OnEvent="Load_Click" />
                                </DirectEvents>
                            </ext:Button>
                        </Items>
                    </ext:Panel>
    
                    <ext:Panel runat="server" Region="Center">
                        <Items>
                            <ext:GridPanel ID="bottomGrid" runat="server" StoreID="strDemo" AutoHeight="true">
                                <ColumnModel ID="ColumnModel1" runat="server">
                                    <Columns>
                                        <ext:DateColumn Header="Day" DataIndex="Date" Format="MM/dd/yyyy" MenuDisabled="true" Sortable="false" />
                                        <ext:DateColumn Header="Time" DataIndex="Date" Format="HH:mm" MenuDisabled="true" Sortable="false" />
                                    </Columns>
                                </ColumnModel>
                                <SelectionModel>
                                    <ext:CellSelectionModel ID="CellSelectionModel1" runat="server">
                                        <DirectEvents>
                                            <CellSelect OnEvent="Cell_Click" />
                                        </DirectEvents>
                                        <Listeners>
                                            <CellSelect Fn="Cell_Listener" />
                                        </Listeners>
                                    </ext:CellSelectionModel>
                                </SelectionModel>
                                <View>
                                    <ext:GroupingView>
                                        <HeaderGroupRows>
                                        </HeaderGroupRows>
                                    </ext:GroupingView>
                                </View>
                            </ext:GridPanel>
    
                        </Items>
                    </ext:Panel>
    
                    <ext:Label runat="server" ID="status" Region="South" Height="100" />
    
                </Items>
            </ext:Viewport>
        </form>
    
    </body>
    </html>
    The top grid, without the group header (Render() is not called), is working fine, but when the group header is used SelectedCell is empty. The Listener works though.

    By the way, does the grid require being inside a <form runat="server"> for the selection model to work? I found out that if it's not inside a form, it doesn't work in either case.

    Thanks and regards,

    Andrew


    PS: After some more testing it seems that the group header is not actually related, but only the addition of columns via ColumnModel + Render(), instead of grid.AddColumn().
    Another finding: if the grid columns are added via the first method and the grid doesn't have a View, none of the two CellSelect events are fired. This is not a problem in my case (my grid has a View), but I just wanted to point this out.

    Second PS: Meanwhile I am using ExtraParams in the DirectEvent to send the missing info to the code behind.
    Last edited by ALobpreis; May 16, 2014 at 12:12 PM.
  8. #28
    I think there was a bug. At least, I cannot reproduce it with the latest v1.x.

    Using ExtraParams is a good workaround.
  9. #29
    Yes, you are right. I tried version 1.2 and it's working properly there. Anyway we will stay with the ExtraParams workaround. Thanks!
Page 3 of 3 FirstFirst 123

Similar Threads

  1. [CLOSED] Dynamic header column component direct event Issue
    By legaldiscovery in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Dec 21, 2015, 10:56 PM
  2. [CLOSED] Problem with TreeGrid Column Header...
    By RCN in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Mar 12, 2012, 1:22 PM
  3. [CLOSED] Problem Creating Dynamic Header column for filter
    By legaldiscovery in forum 1.x Legacy Premium Help
    Replies: 12
    Last Post: Jun 23, 2011, 6:59 AM
  4. Replies: 0
    Last Post: Jun 21, 2011, 12:18 PM
  5. Replies: 0
    Last Post: Feb 17, 2010, 5:38 AM

Tags for this Thread

Posting Permissions