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

Autogenerate columns and modify

6 Answers 56 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.
Patrick Barranis
Top achievements
Rank 1
Patrick Barranis asked on 10 Mar 2011, 04:21 PM
Hi.  I'm using the latest version of the MVC controls on MVC3.  Is it possible to autogenerate the columns but then make modifications?  I only want to hide one column, so it's much faster to autogenerate and then modify rather than write the column bindings from scratch.

If the answer is no, can you please speculate on when you might add a feature to allow it?  I've noticed a number of other forum posts asked about doing something similar.

Thanks!

6 Answers, 1 is accepted

Sort by
0
Accepted
Rosen
Telerik team
answered on 10 Mar 2011, 05:21 PM
Hi Patrick Barranis,

Indeed you can modify setting of the autogenerated columns by supplying a callback to the AutoGenerate method:

<%= Html.Telerik().Grid(Model)
        .Name("Grid")
        .Columns(columns =>
                {  
                    columns.AutoGenerate(column =>
                        {                           
                            column.Width = "150px";
                            if (column.Member == "CustomerID")
                                column.Visible = false;
                        });                       
                })
%>

Please refer to this online demo for more details.


Regards,
Rosen
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Patrick Barranis
Top achievements
Rank 1
answered on 10 Mar 2011, 05:29 PM
Oh, thanks.  I was looking at that overload but I couldn't figure out what it could be used for.  That explains it - thanks!
0
Patrick Barranis
Top achievements
Rank 1
answered on 10 Mar 2011, 07:16 PM
Hi Atanas,

Is it possible to hide a column by this method?  I have the following code in the view:

@(Html.Telerik().Grid<SystemDataViewModel>()
    .Name("SystemData")
    .PrefixUrlParameters(false)
    .Columns(c =>
        c.AutoGenerate(a => { if (a.Member == "ID") a.Hidden = false; }) )
    .DataBinding(b => b.Ajax().Select("UpdateIndexGrid", "SystemData",
        ((QuickFilterModel)ViewBag.QuickFilterModel).GetRouteValues()))
    .HtmlAttributes(new { Class = "NonAjaxSelectionGrid QuickFilterGrid" })
    .Reorderable(r => r.Columns(true))
    .Resizable(r => r.Columns(true))
    .Selectable()
    .Sortable()
    .Pageable(p => p.Style(GridPagerStyles.NextPreviousAndNumeric | GridPagerStyles.PageInput | GridPagerStyles.Status)))

What I get in Chrome is a missing column header with the cell still visible.  In IE the cell is hidden but two column headings are gone ("ID" and the next column after that too).

Is this possible or do I need to "hack it" by putting in cell attributes to hide the cells and whatnot?

Thanks in advance.
0
Patrick Barranis
Top achievements
Rank 1
answered on 10 Mar 2011, 07:45 PM
Hopefully just one last additional question: is there any way to control the order of autogenerated columns?  I tried using the Order property of the DisplayAttribute, and I also tried the Order property of the ColumnAttribute.  Neither seemed to have any effect, even when I specified it on every property in the class.

Thanks.
0
Accepted
Rosen
Telerik team
answered on 11 Mar 2011, 01:05 PM
Hello Patrick Barranis,

I'm afraid that currently there is no way to specify the order in which autogenerated columns will be created.

All the best,
Rosen
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Simon
Top achievements
Rank 1
answered on 11 Nov 2011, 11:21 AM
Hello Rosen,

is is still not possible to specify the order in which autogenerated columns will be created? How is Telerik Grid ordering autogenerated columns anyway?

Thanks for help!

Simon
Tags
Grid
Asked by
Patrick Barranis
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Patrick Barranis
Top achievements
Rank 1
Simon
Top achievements
Rank 1
Share this question
or