Hidding a column

5 posts, 1 answers
  1. tim
    tim avatar
    7 posts
    Member since:
    Mar 2010

    Posted 07 Mar 2011 Link to this post

    I am currently using a column with a boolean value to determine whether to enable/disable certain buttons on the itemselected event client side. The problem I have is that  I do not want to display this column to the user but I can't set visible=false as then the javascript will fail. For a radgrid I can set Display=false, but that option does not seem to exist with a treeList?

    <telerik:RadTreeList ID="radTreeList" runat="server" AutoGenerateColumns="false"
                    AllowPaging="false" PageSize="5" DataKeyNames="ID" ParentDataKeyNames="ParentTemplateId"
                    OnNeedDataSource="radTreeList_NeedDataSource" Skin="Web20">
                    <ClientSettings AllowPostBackOnItemClick="false">
                        <Selecting AllowItemSelection="True" />
                        <ClientEvents OnItemSelected="itemSelected" />
                    </ClientSettings>
                    <Columns>
                        <telerik:TreeListBoundColumn DataField="Name" HeaderText="Name" UniqueName="Name" />
                        <telerik:TreeListBoundColumn DataField="ModifiedTime" HeaderText="ModifiedTime" UniqueName="ModifiedTime" />
                        <telerik:TreeListCheckBoxColumn UniqueName="chkHasChildren" DataField="HasChildren"
                            HeaderText="HasChildren" />
                    </Columns>
                </telerik:RadTreeList>

  2. Veli
    Admin
    Veli avatar
    2002 posts

    Posted 07 Mar 2011 Link to this post

    Hi tim,

    RadTreeList does not currently support hiding columns on the client. You will have to use a different approach for determining your boolean value. You can attach it as an attribute to an HTML element from the server, or add a hidden label to any of your other columns containing your boolean value which you can access on the client.

    Veli
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. tim
    tim avatar
    7 posts
    Member since:
    Mar 2010

    Posted 08 Mar 2011 Link to this post

    Hi Veli,

    Would you be able to provide a quick example of how to a hidden label to one of the other columns?

    Thanks
  5. Answer
    Veli
    Admin
    Veli avatar
    2002 posts

    Posted 08 Mar 2011 Link to this post

    Yes, you can use a TreeListTemplateColumn like follows:

    <telerik:TreeListTemplateColumn DataField="Name"
        HeaderText="Name" UniqueName="NameTemplate">
        <ItemTemplate>
            <%# Eval("Name") %>
            <asp:Label ID="HiddenLabel" runat="server"
                style="display:none">
                <%# Eval("Available") %>
            </asp:Label>
        </ItemTemplate>
    </telerik:TreeListTemplateColumn>

    The column binds to a specified data field (Name in this case) through a binding expression. When rendered, it looks like a regular bound column with text in a cell. However, the cell also contains a hidden label. This label's content is bound to another field (in my case - the boolean Available field). Now each hidden label in each tree list item contains either "True" or "False" as text. On the client, we can retrieve this value, for example in RadTreeList's client-side OnItemClick event:

    <ClientSettings>
        <Selecting AllowItemSelection="true" />
        <ClientEvents OnItemClick="treeListItemClick" />
    </ClientSettings>

    function treeListItemClick(sender, args)
    {
        var row = args.get_item().get_element();
        var hiddenLabel = $telerik.findElement(row, "HiddenLabel");
        alert(hiddenLabel.innerHTML);
    }

    Using $telerik.findElement() I find the hidden label by its server ID and retrieve its innerHTML. The label is not visible, but I get the data I have bound it to.

    Veli
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  6. tim
    tim avatar
    7 posts
    Member since:
    Mar 2010

    Posted 08 Mar 2011 Link to this post

    Thanks Veli.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017