David Geary
Top achievements
Rank 1
David Geary
asked on 07 Feb 2010, 08:33 PM
I have a grid where most of the columns can be hidden by the user, but there are some that should always be visible. Is there a way to specify which columns in a grid can be hidden?
Dave.
Dave.
3 Answers, 1 is accepted
0
Princy
Top achievements
Rank 2
answered on 08 Feb 2010, 07:48 AM
Hi,
You can manipulate the AllowColumnHide property based on the column UniqueName and allow the column to be shown or hidden.
ASPX:
JS
Thanks,
Princy
You can manipulate the AllowColumnHide property based on the column UniqueName and allow the column to be shown or hidden.
ASPX:
| <ClientSettings AllowColumnHide="true"> |
| <ClientEvents /> |
| </ClientSettings> |
JS
| function ShowHide(columnIndex) |
| { |
| var masterTable = $find("<%=RadGrid1.ClientID%>").get_masterTableView(); |
| if (masterTable.get_columns()[columnIndex].get_uniqueName() == "CustomerID") |
| { |
| $find("RadGrid1").ClientSettings.AllowColumnHide = false; |
| masterTable.get_columns()[columnIndex].set_visible(false); |
| } |
| else |
| { |
| $find("RadGrid1").ClientSettings.AllowColumnHide = true; |
| } |
| return false; |
| } |
Thanks,
Princy
0
David Geary
Top achievements
Rank 1
answered on 08 Feb 2010, 08:19 AM
Thanks for the response, Princy, but I'm not sure how you intend the ShowHide() method to be called; is it supposed to be attached to one of the client events?
The aim is to have a column visible in the grid, but just not included in the column list on the column header context menu (ie. so the user can't see it to select/deselect). Is this what your code will do?
Thanks,
Dave.
The aim is to have a column visible in the grid, but just not included in the column list on the column header context menu (ie. so the user can't see it to select/deselect). Is this what your code will do?
Thanks,
Dave.
0
Princy
Top achievements
Rank 2
answered on 09 Feb 2010, 01:28 PM
Hi David,
I have called the ShowHide method on a button click where I pass the column index as parameter.
Try the code snippet below to hide a column from the header context menu list .You will need to wire the OnHeaderShowing client event.
ASPX:
JS:
Thanks,
Princy
I have called the ShowHide method on a button click where I pass the column index as parameter.
Try the code snippet below to hide a column from the header context menu list .You will need to wire the OnHeaderShowing client event.
ASPX:
| <ClientSettings> |
| <ClientEvents OnHeaderMenuShowing="HeaderShowing" /> |
| </ClientSettings> |
JS:
| <script type="text/javascript" language="javascript"> |
| function HeaderShowing(sender, args) { |
| args.get_menu().findItemByText("Columns").get_items().forEach |
| ( |
| function(item) { |
| if (item.get_attributes()._owner._element.innerText == "CustomerID ") |
| item.set_visible(false); |
| else |
| item.set_visible(true); |
| } |
| ); |
| } |
| </script> |
Thanks,
Princy