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

[Solved] Suggestion : "Grouped" property?

1 Answer 62 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.
Dadv
Top achievements
Rank 1
Dadv asked on 09 Jan 2012, 10:53 AM
Hi,

In server side i can "know" that there are some grouping value by doing :

command.GroupDescriptors.Any() where command is GridCommand.

If i found some group descriptors then i return an IEnumerable<AggregateFunctionsGroup> list for the view.

In my view i have something like this :

Html.Telerik().Grid<DocumentModel>()
   .Name("Grid")
   .BindTo(Model)
   .DataKeys(c => c.Add(d => d.DocumentId).RouteKey("DocumentId"))   
   .Columns(columns =>
   {     
       columns.Bound(o => o.DocumentId).Visible(ViewBag.DocumentIdVisible);
       columns.Bound(o => o.Name).Visible(ViewBag.NameVisible);
       columns.Bound(o => o.Validity).Visible(ViewBag.ValidityVisible);
       columns.Command(c => c.Delete().ButtonType(GridButtonType.Image));
   })
       .DataBinding(dataBinding => dataBinding.Server().Select("Document_List", "Documentation").Delete("Document_Delete", "Documentation"))
   .EnableCustomBinding(true)
   .Sortable()
   .Filterable()
   .Groupable()
   .ColumnContextMenu()
   .Pageable(settings => settings.Total(ViewBag.Count).PageSize(ViewBag.PageSize))

My ViewBag content all visibility information, i know that a lot of threads talk about hiding grouping values but i just want to know if you could add a method like
"GroupedVisible(bool value)" / GroupedVisible()
or
Groupedhidden(bool value)" / groupedHidden()
in this case i could stop to create a lot of ViewBag property in server side.

An other possibility is to add a GridVisibleColumnBuilder or a GridHiddenColumnBuilder to the methods Visible() and Hidden():

columns.Bound(o => o.DocumentId).Visible(v => !v.IsGroup); 
columns.Bound(o => o.DocumentId).Hidden(h => !h.IsGroup); 

Please send me your feedback for that functionality,

Regards

PS: I assume that it could probably only work in server side context, not ajax.

1 Answer, 1 is accepted

Sort by
0
Dadv
Top achievements
Rank 1
answered on 09 Jan 2012, 05:02 PM
I just write a simple extension to do the trick :

public static class GroupedVisibleExtension
   {
       public static GridBoundColumnBuilder<T> GroupedVisible<T>(this GridBoundColumnBuilder<T> builder, bool visible) where T: class
       {
           if (builder.Column.Grid.DataProcessor.GroupDescriptors.Any(c => c.Member == builder.Column.Member))
           {
               builder.Column.Visible = builder.Column.Visible && visible;              
           }
 
           return builder;
       }
 
       public static GridBoundColumnBuilder<T> GroupedHidden<T>(this GridBoundColumnBuilder<T> builder, bool hidden) where T : class
       {
           if (builder.Column.Grid.DataProcessor.GroupDescriptors.Any(c => c.Member == builder.Column.Member))
           {
               builder.Column.Hidden = builder.Column.Hidden || hidden;
           }
 
           return builder;
       }
 
   }

Note that the GroupedHidden work fine with the ColumnContextMenu.

Regards,

ps : this thread can be mark as response.
Tags
Grid
Asked by
Dadv
Top achievements
Rank 1
Answers by
Dadv
Top achievements
Rank 1
Share this question
or