This is a migrated thread and some comments may be shown as answers.
Hiding a column in Grid (Extensions for ASP.NET MVC)
3 Answers 166 Views
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Rahul Agashe
Top achievements
Rank 1
Rahul Agashe asked on 01 Dec 2009, 07:38 AM
Hi,

I am using Telerik Extensions for ASP.NET MVC: Grid control.

I am able to hide a particular column by setting its HTML attributes (Style:display:none), but then I noticed that the columns sorting is done as selected column - 1. Means if I try to sort on 4th columns, then actually data is getting sroted on 3rd column.

Below is code for same,

columns.Add(c => c.CalculationID).Title(

"Calculated ID").Sortable(false).HeaderHtmlAttributes(new {@style="display:none;"}).HtmlAttributes(new {@style="display:none;"});

 



3 Answers, 1 is accepted

Sort by
0
Rahul Agashe
Top achievements
Rank 1
answered on 01 Dec 2009, 08:39 AM
Never mind, I figured a solution for the same. I put the hidden column at the end and problem gets resolved.
0
Rahul Agashe
Top achievements
Rank 1
answered on 07 Dec 2009, 07:55 AM
I manage to hide the column, but later I noticed another problem, When user navigate using the paging, and if he reached last page and press prev button, the Hidden column is now visible to the user, which is really weared behaviour grid.

Any suggetions from Telerik side?
0
Atanas Korchev
Telerik team
answered on 07 Dec 2009, 09:20 AM
Hello Rahul Agashe,

I suspect that this occurs because on the last page you have less rows than the page size. Then the grid will remove any unneeded TR tags. After going to another page the grid will create the rows again however the "display:none" setting will be lost hence the last  column will be visible. What I can suggest is use the onRowDataBound event an set the display attribute to none using JavaSript:

.ClientEvents(events => events.OnRowDataBound("onRowDataBound"))

<script type="text/javascript">
    function onRowDataBound(e) {
        e.row.cells[e.row.cells.length - 1].style.display = "none";
    }
</script>

Regards,
Atanas Korchev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
Rahul Agashe
Top achievements
Rank 1
Answers by
Rahul Agashe
Top achievements
Rank 1
Atanas Korchev
Telerik team
Share this question
or