[CLOSED] [1.0] Remove column with dropdown filter below header from GridPanel

  1. #1

    [CLOSED] [1.0] Remove column with dropdown filter below header from GridPanel

    Consider the following grid. I need to be able to remove the Salary column (or at least make it inaccessible) for certain users. How do I do this in code behind?
    The following will successfully remove a column with no HeaderColumns, but causes a script error when there is a HeaderColumn as below.
    gridEmployee.ColumnModel.Columns.RemoveAt(2)

    I assume I also have to remove the filter and HeaderColumn first. How do I do this? Is there an alternative way of making the Salary column inaccessible?
     <ext:GridPanel ID="gridEmployee" StoreID="stoEmployee" runat="server" Width="600">
                <ColumnModel runat="server">
                    <Columns> 
                        <ext:Column DataIndex="EmployeeID" Header="Employee ID"/>
                        <ext:Column DataIndex="Name" Header="Name" />
                        <ext:Column DataIndex="Salary" Header="Salary" />
                     </Columns>
                </ColumnModel>
                <View>
                    <ext:GridView ID="viewEmployee" runat="server">
                        <HeaderRows>
                            <ext:HeaderRow>
                                <Columns>
                                    <ext:HeaderColumn>
                                        <Component>                              
                                            <ext:TextField ID="fltr1" runat="server"  />
                                        </Component>
                                    </ext:HeaderColumn>
                                    <ext:HeaderColumn>
                                        <Component>
                                            <ext:TextField ID="fltr2" runat="server" />
                                        </Component>
                                    </ext:HeaderColumn>
                                    <ext:HeaderColumn>
                                        <Component>
                                            <ext:TextField ID="fltr3" runat="server" />
                                        </Component>
                                    </ext:HeaderColumn>
                                 </Columns>
                            </ext:HeaderRow>
                        </HeaderRows>
                    </ext:GridView>
                </View>
            </ext:GridPanel>
    Last edited by Daniil; Oct 25, 2010 at 8:57 PM. Reason: [CLOSED]
  2. #2
    Hi betamax,

    What about just hiding a column?
    GridPanel1.ColumnModel.Columns[2].Hidden = true;
    An addition benefit would be having an easy way to show this column dynamically.
  3. #3
    Clicking the right-side of each column header allows you to set which columns are visible - including hidden ones. So if the salary column in the sample is set to hidden there is nothing to stop the user making it visible. In this instance the Salary column needs to be set so the user can never access it
    Last edited by betamax; Oct 25, 2010 at 7:35 PM. Reason: clarification
  4. #4
    Hi,

    When you remove the column? During DirectEvent or initial page load? If during initial page load then you have to remove appropriate HeaderColumn in the HeaderRow also
  5. #5
    Quote Originally Posted by Vladimir View Post
    When you remove the column? During DirectEvent or initial page load? If during initial page load then you have to remove appropriate HeaderColumn in the HeaderRow also
    in page load.

    I am aware of that. My question is how to do this? How do you remove the header column and filter in the initial page load?
    IOW, I just need the syntax for removing the Header Column and filter, so that the column can be subsequently removed.
  6. #6
    Please look at the example.

    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[] {"test11", "test12", "test13"},
                                             new object[] {"test21", "test22", "test23"},
                                             new object[] {"test31", "test32", "test33"}
                                    };
                store.DataBind();
                GridPanel1.ColumnModel.Columns.RemoveAt(2);
                GridPanel1.Items.Remove(TextField1);
                GridPanel1.View.View.HeaderRows[0].Columns.RemoveAt(2);
            }
        }
    </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>
        <form runat="server">
        <ext:ResourceManager runat="server" />
        <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:Column Header="Test3" DataIndex="test3" />
                </Columns>
            </ColumnModel>
            <View>
                <ext:GridView runat="server">
                    <HeaderRows>
                        <ext:HeaderRow>
                            <Columns>
                                <ext:HeaderColumn>
                                    <Component>
                                        <ext:TextField runat="server" />
                                    </Component>
                                </ext:HeaderColumn>
                                <ext:HeaderColumn>
                                    <Component>
                                        <ext:TextField runat="server" />
                                    </Component>
                                </ext:HeaderColumn>
                                <ext:HeaderColumn>
                                    <Component>
                                        <ext:TextField ID="TextField1" runat="server" />
                                    </Component>
                                </ext:HeaderColumn>
                            </Columns>
                        </ext:HeaderRow>
                    </HeaderRows>
                </ext:GridView>
            </View>
        </ext:GridPanel>
        </form>
    </body>
    </html>
  7. #7

    [CLOSED] thanks

    Very nice example. That works fine. Much appreciated.
  8. #8
    Can I use DirectEvent of textbox in Header???
  9. #9
    Quote Originally Posted by hazardvn View Post
    Can I use DirectEvent of textbox in Header???
    Please start a new forum thread.

Similar Threads

  1. ¿ GridView how to hide the column header filter ?
    By xtremexploit in forum 1.x Help
    Replies: 6
    Last Post: May 07, 2012, 3:24 PM
  2. Replies: 6
    Last Post: Jan 28, 2012, 1:14 AM
  3. Replies: 3
    Last Post: Aug 13, 2010, 4:25 PM
  4. [CLOSED] gridpanel header menu column checkbox remove
    By majestic in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Oct 15, 2009, 11:28 AM
  5. [CLOSED] Add filter button to grid column header
    By jchau in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jul 08, 2009, 10:10 AM

Posting Permissions