This is a migrated thread and some comments may be shown as answers.

Hide/Unhide columns

7 Answers 187 Views
Grid
This is a migrated thread and some comments may be shown as answers.
KC
Top achievements
Rank 1
KC asked on 18 Feb 2011, 08:17 PM
Hi,

As mentioned in a previous thread, am using the solution in this thread to hide/ unhide columns.

In my scenario, out of the 10 columns in the grid am displaying 6 when am first loading the page. Am using checkboxes to hide/unhide each column.

Am facing a problem displaying the columns that are hidden on pageload. Am able to hide/unhide the 6 columns that are displayed on page load. Am guessing this might be due to the viewstate too.

Any suggestions to fix this would be helpful.

Thank you.

7 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 21 Feb 2011, 12:19 PM
Hello KC,

Give a try with the following code snippet to show the column which is hide initially.

ASPX:
<telerik:GridBoundColumn DataField="FirstName" HeaderText="FirstName" UniqueName="FirstName"
    Display="false">
</telerik:GridBoundColumn>

Java Script:
<script type="text/javascript">
      function showColumn() {
         var radGrid = $find('<%= RadGrid1.ClientID %>');
        var table = radGrid.get_masterTableView();
        var columns = table.get_columns();
        for (idx = 0; idx < columns.length; idx++) {
            var column = columns[idx];
            if (column.get_uniqueName() == "FirstName") {
                table.showColumn(idx);
            }
        }
      }
</script>

-Shinu.
0
KC
Top achievements
Rank 1
answered on 21 Feb 2011, 08:34 PM
Hi Shinu,

Thank you for the reply.

I tried out the code snippet you provided. It still does not work.

I placed an alert with columns.length and it returned the number of visible columns instead of total number of columns.

Is there any other function that would return all the columns(including the hidden ones?)

Thanks again!
0
Accepted
Shinu
Top achievements
Rank 2
answered on 22 Feb 2011, 09:24 AM
Hello KC,

The above code(columns.length)  will return total number of columns if you are using 'Display="false" property to hide the column. Check whether you have used Visible property to hide the column. If so use Display property and see if it works. Hope this information helps.

ASPX:
<telerik:GridBoundColumn DataField="FirstName"  UniqueName="FirstName"
    Display="false">
</telerik:GridBoundColumn>

-Shinu.
0
KC
Top achievements
Rank 1
answered on 22 Feb 2011, 08:03 PM
Thanks a lot, Shinu! Works fine now..
0
David
Top achievements
Rank 1
answered on 23 Jun 2011, 01:01 AM

Is there any way to hide a column for a specific row?
What I am ultimately trying to do is hide a control until a button in another column in the same row is clicked.
Referring to my code below I want to show the LinkButton 'LinkButtonSelectPerson' when the other LinkButton 'LinkButtonViewPerson' is clicked.

Thanks,

David

function DoIt(pid) {
        var grid = $find("<%=GridClientSearchResults.ClientID %>");
        var MyControl = $telerik.findControl(grid, "LinkButtonSelectPerson");
        MyControl.style.display = 'block';
    }

<telerik:RadGrid ID="GridClientSearchResults" runat="server" LocalizationPath="~/App_LocalResources"
                    EnableLinqExpressions="false" AllowPaging="true" AutoGenerateColumns="False"
                    GridLines="None" MasterTableView-DataKeyNames="PartyID" OnPageIndexChanged="GridClientSearchResults_PageIndexChanged"
                    OnItemCommand="GridClientSearchResults_ItemCommand" Skin="Windows7" PageSize="<%$appSettings:GridPageSize %>"
                    OnItemDataBound="GridClientSearchResults_ItemDataBound">
                    <MasterTableView>
                        <CommandItemSettings ExportToPdfText="Export to Pdf"></CommandItemSettings>
                        <RowIndicatorColumn>
                            <HeaderStyle Width="20px"></HeaderStyle>
                        </RowIndicatorColumn>
                        <ExpandCollapseColumn>
                            <HeaderStyle Width="20px"></HeaderStyle>
                        </ExpandCollapseColumn>
                        <Columns>
                            <telerik:GridTemplateColumn>
                                <ItemTemplate>
                                    <asp:LinkButton ID="LinkButtonSelectPerson" Text="<%$ Resources:KEY_BTN_SELECT %>" Visible="false"
                                        runat="server" ></asp:LinkButton>
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn>
                                <ItemTemplate>
                                    <asp:LinkButton ID="LinkButtonViewPerson" OnClientClick="DoIt('<%# DataBinder.Eval(Container.DataItem,"PartyID")%>')" Text="<%$ Resources:KEY_BTN_VIEW_CLIENT %>" runat="server" CommandName="View" ></asp:LinkButton>
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn UniqueName="PartyID" DataField="PartyID" HeaderText="" Visible="false">
                            </telerik:GridBoundColumn>
                        </Columns>
                    </MasterTableView>
                </telerik:RadGrid>

0
Iana Tsolova
Telerik team
answered on 23 Jun 2011, 09:24 AM
Hello David,

I would suggest that you modify your code as below:
<asp:LinkButton ID="LinkButtonViewPerson" OnClientClick="DoIt(this, '<%# DataBinder.Eval(Container.DataItem,"PartyID")%>')" Text="<%$ Resources:KEY_BTN_VIEW_CLIENT %>" runat="server" CommandName="View" ></asp:LinkButton>


function DoIt(sender, pid) {
         var LinkButtonViewPerson = sender;
         var MyControl = $find(sender.id.replace("LinkButtonViewPerson", "LinkButtonSelectPerson"));
         MyControl.style.display = 'block';
     }


Let me know if it works for you.

Kind regards,
Iana
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
David
Top achievements
Rank 1
answered on 23 Jun 2011, 11:51 PM
With a slight modification it worked like a charm. Very slick way of finding a control in the same area of the control hierarchy,  thank you so much.
It turns out the $find method returned null so I changed $find to $get and that was all I had to modify.

Thanks again,

David
Tags
Grid
Asked by
KC
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
KC
Top achievements
Rank 1
David
Top achievements
Rank 1
Iana Tsolova
Telerik team
Share this question
or