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

[Solved] Can't hide grid column

3 Answers 142 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.
Project House
Top achievements
Rank 1
Project House asked on 23 Dec 2010, 03:22 PM
Hi,
I bound a data table to grid which columns are dynamically created. I want to hide "Id" column in grid. Sample code is below;

<%: Html.Telerik().Grid(Model.ResultList)
.Name("GridBounceList")
.CellAction(cells =>
{
if(cells.Column.Title=="Id")
cells.Column.Hidden = true;
})
.DataBinding(db => db.Ajax().Select("_BindBounceList", "Report"))
.Pageable(paging => paging.PageSize(20).Style(GridPagerStyles.PageInput | GridPagerStyles.Numeric).Position(GridPagerPosition.Bottom))
.Sortable(sorting => sorting.SortMode(GridSortMode.MultipleColumn))
.Filterable()
%>

Any help would be greatly appreciated.

Thank you.

3 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 23 Dec 2010, 03:44 PM
Hello Onur Buyukcaglar,

 Could you try this :

if(cells.Column.Title=="Id")
{
cells.Column.Hidden = true;
cells.HtmlAttributes["style"] = "display:none";
}

If you don't want to render the column at all use the Visible property and set it to false:
if(cells.Column.Title=="Id")
{
cells.Column.Visible = false;
}

You can access the whole data item on the client side so perhaps you don't need the hidden column. To get the data item for a particular row use the dataItem function. Here is a quick JavaScript code snippet:

var grid = $('#Grid').data('tGrid');
var tr = $('#Grid tr:has(td)').eq(1); // the second row
var dataItem  = grid.dataItem(tr);


Regards,
Atanas Korchev
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
Project House
Top achievements
Rank 1
answered on 23 Dec 2010, 04:38 PM
if(cells.Column.Title=="Id")
{
cells.Column.Hidden = true;
cells.HtmlAttributes["style"] = "display:none";
}

After we use the code block above, the resulting screen shot can be found below;

Before use;
firstLook.jpg

After use;
afterLook.jpeg

Thanks
0
Atanas Korchev
Telerik team
answered on 23 Dec 2010, 04:55 PM
Hello Onur Buyukcaglar,

 After investigating this further I discovered that it is too late to hide a column during CellAction. It occurs after the header has been rendered thus it cannot be hidden.

 Unfortunately there is no workaround for this case apart from hiding the column with JavaScript:

        .ClientEvents(e => e.OnLoad("onLoad"))
%>
    <script type="text/javascript">
    function onLoad() {
        $('#Grid colgroup').find('col:eq(0)').hide();
        $('#Grid tr:has(th)').find('th:eq(0)').hide();
        $('#Grid tr:has(td)').find('td:eq(0)').hide();
    }
    </script>
This code will hide the first column of the grid whose name is "Grid".

Regards,
Atanas Korchev
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
Tags
Grid
Asked by
Project House
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Project House
Top achievements
Rank 1
Share this question
or