Hello all,
i am using rad grid with contextmenu to show and hide columns
when i hide all columns the contextmenu disapear and i am not able to add columns again
i am using javascript function to restore all columns
function RestoreColumns() {
var grid = $find("<%=RadGrid1.ClientID %>");
for (i = 0; i < grid.get_masterTableView().get_columns().length; i++) {
grid.get_masterTableView().showColumn(i);
}
}
how can i use my script or check if number of radgrid columns equal to 0 (no columns) so i can display the context menu again
or use a visible button to show all columns
Any suggestions or help will be appreciated !
10 Answers, 1 is accepted
0

Shinu
Top achievements
Rank 2
answered on 19 Jul 2010, 01:33 PM
Hello Sam,
Access the column form client and use the set_visible() method to set the column visible.
Client Side:
I hope the example is enough for you. :)
-Shinu.
Access the column form client and use the set_visible() method to set the column visible.
Client Side:
function
setVisible() {
var
grid = $find(
'<%=RadGrid1.ClientID %>'
); grid.get_masterTableView().getColumnByUniqueName(
"CustomerID"
).set_visible(
true
);
}
I hope the example is enough for you. :)
-Shinu.
0

sam
Top achievements
Rank 1
answered on 19 Jul 2010, 09:18 PM
Hi Shinu thanks for your suggestion
but can you please tell me more from where to call this function ?
My main problem is when i deselect or hide all columns from the context menu
the RadGrid is not shown also the contextmenu please keep in mind that i am using RadGrid Automatic Operations in my ASP page
in this case i need to display the contextmenu so i can add at least one column >>> radgrid will appear again )
this is the code i am using
<telerik:RadGrid ID="RadGrid1" runat="server" AllowFilteringByColumn="True" AllowPaging="True"
AllowSorting="True" DataSourceID="SqlDataSource1" GridLines="None" AutoGenerateDeleteColumn="True"
AutoGenerateEditColumn="True" AllowAutomaticInserts="True" AllowAutomaticUpdates="True"
Skin="Inox" AllowAutomaticDeletes="True" AllowMultiRowEdit="True"
EnableHeaderContextMenu="True" TableLayout="Fixed">
<HeaderContextMenu EnableTheming="True">
<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>
</HeaderContextMenu>
<MasterTableView DataKeyNames="model_code" DataSourceID="SqlDataSource1" GridLines="None"
CommandItemDisplay="Top" EditMode="PopUp" AutoGenerateColumns="False">
<RowIndicatorColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>
<ExpandCollapseColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
<Columns>
<telerik:GridTemplateColumn DataField="manufacturer_code" HeaderText="Manufacturer code"
SortExpression="manufacturer_code" UniqueName="manufacturer_code">
<EditItemTemplate>
<asp:TextBox ID="manufacturer_codeTextBox" runat="server" Text='<%# Bind("manufacturer_code") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="manufacturer_codeTextBox"
ErrorMessage="Manufacturer code is required !"></asp:RequiredFieldValidator>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="manufacturer_codeLabel" runat="server" Text='<%# Eval("manufacturer_code") %>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn DataField="model_name" HeaderText="Model name" SortExpression="model_name"
UniqueName="model_name">
<EditItemTemplate>
<asp:TextBox ID="model_nameTextBox" runat="server" Text='<%# Bind("model_name") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="model_nameTextBox"
ErrorMessage="Model name is required !"></asp:RequiredFieldValidator>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="model_nameLabel" runat="server" Text='<%# Eval("model_name") %>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
<ClientSettings AllowColumnHide="true">
<ClientEvents OnColumnContextMenu="ColumnContextMenu" />
</ClientSettings>
<FilterMenu EnableTheming="True">
<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>
</FilterMenu>
</telerik:RadGrid>
but can you please tell me more from where to call this function ?
My main problem is when i deselect or hide all columns from the context menu
the RadGrid is not shown also the contextmenu please keep in mind that i am using RadGrid Automatic Operations in my ASP page
in this case i need to display the contextmenu so i can add at least one column >>> radgrid will appear again )
this is the code i am using
<telerik:RadGrid ID="RadGrid1" runat="server" AllowFilteringByColumn="True" AllowPaging="True"
AllowSorting="True" DataSourceID="SqlDataSource1" GridLines="None" AutoGenerateDeleteColumn="True"
AutoGenerateEditColumn="True" AllowAutomaticInserts="True" AllowAutomaticUpdates="True"
Skin="Inox" AllowAutomaticDeletes="True" AllowMultiRowEdit="True"
EnableHeaderContextMenu="True" TableLayout="Fixed">
<HeaderContextMenu EnableTheming="True">
<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>
</HeaderContextMenu>
<MasterTableView DataKeyNames="model_code" DataSourceID="SqlDataSource1" GridLines="None"
CommandItemDisplay="Top" EditMode="PopUp" AutoGenerateColumns="False">
<RowIndicatorColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>
<ExpandCollapseColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
<Columns>
<telerik:GridTemplateColumn DataField="manufacturer_code" HeaderText="Manufacturer code"
SortExpression="manufacturer_code" UniqueName="manufacturer_code">
<EditItemTemplate>
<asp:TextBox ID="manufacturer_codeTextBox" runat="server" Text='<%# Bind("manufacturer_code") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="manufacturer_codeTextBox"
ErrorMessage="Manufacturer code is required !"></asp:RequiredFieldValidator>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="manufacturer_codeLabel" runat="server" Text='<%# Eval("manufacturer_code") %>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn DataField="model_name" HeaderText="Model name" SortExpression="model_name"
UniqueName="model_name">
<EditItemTemplate>
<asp:TextBox ID="model_nameTextBox" runat="server" Text='<%# Bind("model_name") %>'></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="model_nameTextBox"
ErrorMessage="Model name is required !"></asp:RequiredFieldValidator>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="model_nameLabel" runat="server" Text='<%# Eval("model_name") %>'></asp:Label>
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
<ClientSettings AllowColumnHide="true">
<ClientEvents OnColumnContextMenu="ColumnContextMenu" />
</ClientSettings>
<FilterMenu EnableTheming="True">
<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>
</FilterMenu>
</telerik:RadGrid>
0
Hello sam,
Sincerely yours,
Maria Ilieva
the Telerik team
Please find attached a sample application which should covers your requirements. Test it on your side and let me know if it helps.
Sincerely yours,
Maria Ilieva
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0

sam
Top achievements
Rank 1
answered on 23 Jul 2010, 07:54 AM
Hi Maria ,
Thank you very much but i didn t solve the problem and i used your script and I got the same result I have from the beginning
please try your attached simple....WHAT HAPPEN IF YOU HIDE ALL COLUMNS?!?!?!?!
You will notice that only footer of the Radgrid is displayed and you will not be able to access the context menu again also you will not be able to add a column
My main problem is when i deselect or hide all columns from the context menu
the RadGrid is not shown also the contextmenu
Please Help !
Thank you very much but i didn t solve the problem and i used your script and I got the same result I have from the beginning
please try your attached simple....WHAT HAPPEN IF YOU HIDE ALL COLUMNS?!?!?!?!
You will notice that only footer of the Radgrid is displayed and you will not be able to access the context menu again also you will not be able to add a column
My main problem is when i deselect or hide all columns from the context menu
the RadGrid is not shown also the contextmenu
Please Help !
0
Hello sam,
In your scenario I would suggest you to use the RadGrid HeaderContextMenu by setting the EnableHeaderContextMenu to "true" Please refer to the following online demo for more information on this approach.
Regards,
Maria Ilieva
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0

sam
Top achievements
Rank 1
answered on 26 Jul 2010, 04:55 PM
Thanka Maria I already tried the sample demo before
still no chance ...(
The demo works fine because it contains sub gridview and detail tables it is not similar to my case
Regards
still no chance ...(
The demo works fine because it contains sub gridview and detail tables it is not similar to my case
Regards
0
Accepted
Hi sam,
One possible option for achieving the required functionality you could add NoRecordsTemplate with a label in it and use this control as target element for the ContextMenu. Please find a sample code below:
ASPX:
CS:
Let us know if this helps.
Sincerely yours,
Maria Ilieva
the Telerik team
One possible option for achieving the required functionality you could add NoRecordsTemplate with a label in it and use this control as target element for the ContextMenu. Please find a sample code below:
ASPX:
<
NoRecordsTemplate
>
<
asp:Label
ID
=
"Label1"
runat
=
"server"
Text
=
"No records to display"
></
asp:Label
>
</
NoRecordsTemplate
>
CS:
protected
void
RadGrid1_ItemCreated(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridNoRecordsItem)
{
Label lbl = (e.Item
as
GridNoRecordsItem).FindControl(
"Label1"
)
as
Label;
ContextMenuElementTarget target =
new
ContextMenuElementTarget();
target.ElementID = lbl.ClientID;
RadMenu1.Targets.Add(target);
}
}
Let us know if this helps.
Sincerely yours,
Maria Ilieva
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0

sam
Top achievements
Rank 1
answered on 28 Jul 2010, 08:32 PM
Thank you Maria,
I tried it but no luck (
is there any property instead of <NoRecordsTemplate> maybe <NoColumn>????!
<MasterTableView DataKeyNames="IDCountry" DataSourceID="SqlDataSource1" GridLines="None"
CommandItemDisplay="Top" EditMode="PopUp" AutoGenerateColumns="False"
>
<NoRecordsTemplate>
<asp:Label ID="Label1" runat="server" Text="No records to display"></asp:Label>
</NoRecordsTemplate>
No column means no records to display .Ok ...but didn t work :((((
please find attached RadGridcontextmenu to see the captured image
in capture3 is the problem where I can not call or use right click (context menu) because no column is displayed
Thank you in return for always helping me
please keep in mind NO column instead of <NoRecordsTemplate>
waiting your reply )
I tried it but no luck (
is there any property instead of <NoRecordsTemplate> maybe <NoColumn>????!
<MasterTableView DataKeyNames="IDCountry" DataSourceID="SqlDataSource1" GridLines="None"
CommandItemDisplay="Top" EditMode="PopUp" AutoGenerateColumns="False"
>
<NoRecordsTemplate>
<asp:Label ID="Label1" runat="server" Text="No records to display"></asp:Label>
</NoRecordsTemplate>
No column means no records to display .Ok ...but didn t work :((((
please find attached RadGridcontextmenu to see the captured image
in capture3 is the problem where I can not call or use right click (context menu) because no column is displayed
Thank you in return for always helping me
please keep in mind NO column instead of <NoRecordsTemplate>
waiting your reply )
0
Hi sam,
Currently the proposed solution is the only way for achieving the required functionality. You could not set NoColumn template instead of the implemented NoRecords template of the RadGrid.
Regards,
Maria Ilieva
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0

sam
Top achievements
Rank 1
answered on 02 Aug 2010, 04:25 PM
Hi Maria
Thanks for your support
to be fair i will mark your answered )
but i will stay subscribed to the forum until someone have another solution
Thanks again
Thanks for your support
to be fair i will mark your answered )
but i will stay subscribed to the forum until someone have another solution
Thanks again