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

[Solved] GridCommand woes, when pre defining sorting

2 Answers 73 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Stefan
Top achievements
Rank 1
Stefan asked on 19 May 2011, 05:14 PM
Hello!

I'm using a Grid with a Custom Server Binding, largely how you do in the examples, just with a little bit more code to provide server-side defaults for filtering, sorting and grouping, and pushing those through a ViewModel to the client and applying them to the Grid, so the UI is in sync with the data displayed.

The problem is, you can't tell from the GridCommand if any of the Descriptors are not set or if the client simple removed any sorting from the grid, since in both cases the properties are populated with an empty List<T>, so there is no way of telling if the empty list of Descriptors or the Defaults apply. See example below.

My approach to change this would be to extend the GridActionAttribute and change the way the GridCommand is built (null / empty Lists respective to if empty descriptors have been supplied or none at all), which seems a little bit like overkill.

Any simpler suggestions than this?

Controller:
        [GridAction(GridName = "user-grid")]
        public ActionResult Index(GridCommand command)
        {
            var vm = new UserGridViewModel().ApplyGridCommand(command); 

            (yadda, yadda, yadda...)

            return View(vm);
        }

ViewModel:
    public class GridViewModel
    {
	(yadda, yadda...)
 
        public GridViewModel ApplyGridCommand(GridCommand command)
        {
            Page = !command.IsEmpty() && command.Page > 0 ? command.Page : Page;
            PageSize = !command.IsEmpty() ? command.PageSize : PageSize;

	    // No way of telling if Descriptors have been removed (orderBy=~) or if there are none set and Defaults should be applied,
            // since command.SortDescriptors is always an empty list in both cases.
            SortDescriptors = !command.IsEmpty() && command.SortDescriptors.Any() ? command.SortDescriptors : SortDescriptors;
           
            return this;
        }
    }
 
    public class UserGridViewModel : GridViewModel
    {
        public UserGridViewModel()
        {
            SortDescriptors.Add(new SortDescriptor
            {
                Member = "Name"
            });
        }
    }

	// Other *GridViewModel with different defaults

2 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 20 May 2011, 01:33 PM
Hello Stefan,

 Indeed empty collection of descriptors is always provided no matter if the default ones are used or none at all. Unfortunately we haven't found a non-ambiguous way to tell the user which is which. If we decide to set the descriptors to null in certain cases we will introduce a breaking change which will cause a NullReferenceException. 

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
Stefan
Top achievements
Rank 1
answered on 20 May 2011, 02:08 PM
So extending the GridActionAttribute it is then, for now at least.
Would be great if you could find a way to accomplish this for future versions somehow, though.
Tags
General Discussions
Asked by
Stefan
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Stefan
Top achievements
Rank 1
Share this question
or