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

[Solved] Can grouped column be initially sorted descending?

13 Answers 174 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.
William Brown
Top achievements
Rank 1
William Brown asked on 02 Sep 2010, 01:20 AM
We have a grouped column:
.Groupable(grouping => grouping.Enabled(Model.GridProperty.Grouping))
.Groupable(grouping => grouping.Groups(groups => groups.Add(c => 
c.PackageDate)))

But I want it sorted descending initially by PackageDate.  Is that possible to set on the initial rendering in the ASPX?  I tried adding a sortby that column descending, but it didn't work.

I click the group header column and it will sort the grouping descending and when I view the page source I see:

GridCasePreviousSubmissionList-groupBy=PackageDate-asc"><


That's how I'd like the initial group to display.  Any way to do this?

Thanks,

Bill

13 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 02 Sep 2010, 08:05 AM
Hello William Brown,

 Unfortunately this is currently not possible. However you can easily implement it like this:

  1. Open GridGroupDescriptorFactory.cs
  2. Create a new overload of the Add method:
    public GridGroupDescriptorBuilder<TModel> Add<TValue>(Expression<Func<TModel, TValue>> expression, ListSortDirection sortDirection)
    {
        GroupDescriptor descriptor = new GroupDescriptor();
        descriptor.Member = expression.MemberWithoutInstance();
        descriptor.SortDirection = sortDirection;
        descriptor.MemberType = typeof(TValue);
         
        settings.Groups.Add(descriptor);
     
        return new GridGroupDescriptorBuilder<TModel>(descriptor);
    }


Then you can use it like this:
grouping.Groups(groups => groups.Add(c=> c.PackageDate, ListSortDirection.Descending)

Best wishes,
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
William Brown
Top achievements
Rank 1
answered on 02 Sep 2010, 02:38 PM
Thanks Atanas,

Where do i find GridGroupDescriptorFactory.cs in the project?  I see telerik.grid.grouping.min.cs but cannot see the file you mention. Thanks for your quick solution, I look forward to trying it out!

Bill
0
Atanas Korchev
Telerik team
answered on 02 Sep 2010, 03:28 PM
Hello William Brown,

The file is in [install location]Source\Telerik.Web.Mvc\UI\Grid\Fluent\

All the best,
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
William Brown
Top achievements
Rank 1
answered on 02 Sep 2010, 03:40 PM
Thanks Atanas!
 
I installed manually under program files  over our previous release. Once I make the change you suggest, how do I integrate it in my project?  My project only references the telerik dll and includes the scripts folder and content styles.  Do I need to rebuild the Telerik.Web.Mvc.dll?


Bill
0
Atanas Korchev
Telerik team
answered on 02 Sep 2010, 03:44 PM
Hello William Brown,

Since this is a modification to the source code you need to rebuild the solution (make sure you have set the proper build configuration first) and then use the output assembly in your project.

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
William Brown
Top achievements
Rank 1
answered on 03 Sep 2010, 12:06 AM
Hello Atanas,

See attached picture.

I tried modifying the code, but I"m not good w/ generics.  I added the missing using clauses.  The <TModel> is giving me issues and the settings. is giving me issues.  Do I need to add a reference or is this supposed to be something else?

I tried changing it to "T" defined above, but it didn't know what settings.Groups.Add is.

Thanks for you help
0
Atanas Korchev
Telerik team
answered on 03 Sep 2010, 07:36 AM
Hi William Brown,

 The screenshot shows that you are editing a different file. You should add the method in GridGroupDescriptorFactory.cs not in GridGroupDescriptorBuilder.cs.

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
William Brown
Top achievements
Rank 1
answered on 03 Sep 2010, 05:34 PM
Sorry, you are right!  I clicked on the wrong class.  after adding the new method, the build wont' compile with errors in ViewComponentFactory.cs - RangeAdapter cannot be found.


What references do I need or am I missing?  Is there a help document on compiling the Telerik MVC dll itself?  In the app I don't see missing references that are incorrect.

Bill
0
William Brown
Top achievements
Rank 1
answered on 03 Sep 2010, 05:36 PM
Is RangeAttributeAdapter a new mvc class?  I can't seem to find it.
0
Atanas Korchev
Telerik team
answered on 06 Sep 2010, 07:40 AM
Hello William Brown,

 You need to change the build configuration to Release MVC2 NET35.

All the best,
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
William Brown
Top achievements
Rank 1
answered on 07 Sep 2010, 04:48 PM
Hi Atanas,

I do have settings set to Release MVC2 NET35  and get the error i describe. see attached picture of settings and errors when building on the bottom.  if you can build this with the code inserted and just send me the dll I'd be happy for now for this customer. if not, let me know what i can do to get it built.

Thanks

Bill
0
Accepted
Atanas Korchev
Telerik team
answered on 07 Sep 2010, 04:59 PM
Hi William Brown,

 That's odd. After changing the solution build configuration (not the project) I was able to build it successfully.

Anyway here is how to group by descendingly without modifying the source code:

<%
    var gridBuilder = Html.Telerik().Grid<Order>(Model)
        .Name("Grid")
        .Columns(columns =>
        {
            columns.Bound(o => o.OrderID).Width(100);
            columns.Bound(o => o.Customer.ContactName).Width(200);
            columns.Bound(o => o.ShipAddress);
            columns.Bound(o => o.OrderDate).Format("{0:MM/dd/yyyy}").Width(120);
        })
        .Groupable(settings => settings.Groups(groups =>
        {
            groups.Add(o => o.OrderDate);
        }))
        .DataBinding(dataBinding => dataBinding.Ajax().Select("GroupingAjax", "Grid"))
        .Scrollable()
        .Sortable()
        .Pageable()
        .Filterable();
 
  var grid = gridBuilder.ToComponent();
  grid.Grouping.Groups[0].SortDirection = System.ComponentModel.ListSortDirection.Descending;
  gridBuilder.Render();
             
%>

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
William Brown
Top achievements
Rank 1
answered on 07 Sep 2010, 06:26 PM
This works great and is better than recompiling the dll. thanks!
Tags
Grid
Asked by
William Brown
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
William Brown
Top achievements
Rank 1
Share this question
or