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

[Solved] How can I hide grid columns via javascript?

4 Answers 188 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Matthew
Top achievements
Rank 1
Matthew asked on 31 Oct 2011, 04:17 AM
What is the best way to hide grid columns for an MVC grid at runtime via javascript?  I essentially want to have a drop down and hide all columns not selected by the drop down list.

4 Answers, 1 is accepted

Sort by
0
Matthew
Top achievements
Rank 1
answered on 01 Nov 2011, 12:16 AM
Ok I figured out I can do it with the following code

[code]
@{Html.Telerik().ScriptRegistrar().OnDocumentReady(
@<text>
    $('#Grid th:eq(2)').hide();
    $('#Grid tr td:eq(2)').hide();
</text>
);}
[/code]

While these individual scripts work, they don't work on document ready.  When this is run on document ready, the first line works to correctly hide the header, but the data cells are still visible.  In the debugger I can run the 2nd line again it correctly removes the data cells.

How can I get this to work correctly on document load, without resorting to .Hidden(true) on the actual grid code
0
Georgi Tunev
Telerik team
answered on 01 Nov 2011, 04:18 PM
Hi Matthew,

The code works as expected on my side - it hides the header and the first cell under it. If you want to hide the whole column, you should try something like this:

$('#OrdersGrid th:eq(2)').hide();
$('#OrdersGrid tr td:nth-child(3n)').hide();


I hope this helps. If you still need assistance, could you please send a sample project that shows your exact setup?


Regards,
Georgi Tunev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
Jerry
Top achievements
Rank 1
answered on 17 Nov 2011, 12:02 AM
Hi there,


Is it possible to hide/display a column based on its column name?

If so, could you give me one example?


Thank you.
Jerry
0
Nikolay Rusev
Telerik team
answered on 17 Nov 2011, 08:19 AM
Hello Jerry,

With Q3 Release of Telerik Extensions for ASP.NET MVC which happened yesterday we introduced client API for showing/hiding columns. I.e grid.showColumn/hideColumn("column name")

There is also a column header context menu for showing/hiding columns. You can see more on the demo bellow:http://demos.telerik.com/aspnet-mvc/grid/columncontextmenu


Greetings,
Nikolay Rusev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
Tags
Grid
Asked by
Matthew
Top achievements
Rank 1
Answers by
Matthew
Top achievements
Rank 1
Georgi Tunev
Telerik team
Jerry
Top achievements
Rank 1
Nikolay Rusev
Telerik team
Share this question
or