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

[Solved] Error when switching sort order multiple times

0 Answers 31 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.
Bruce
Top achievements
Rank 1
Bruce asked on 25 Feb 2012, 09:36 PM
I have setup a grid that uses an IQueryable<CustomerContact> model that has sorting enabled and
it displays correctly and you can change the sort order without issue until you try to switch the sort order
on a single column three times in succession.  The sorting switches from ascending to descending to
none and the Grid and GridModel throw an exception when the sort order is set to none.

The query strings look like the following for example:

?CustomerList-orderBy=Customer.CustomerID-asc
?CustomerList-orderBy=Customer.CustomerID-desc
?CustomerList-orderBy=~

The sorting expression on the Grid is the following:

.Sortable(sorting => sorting

     .OrderBy(sortOrder => sortOrder.Add(o => o.Customer.StartDate).Descending())

)

The specific exception is shown below.  I've tried to handle the sorting before passing the IQueryable
to the grid but it appears the grid removes the order by clause and the exception still occurs.  It would
appear that the Grid/GridModel is handling the option where sorting is set to "~" incorrectly -- an
ordering is required for the grid paging so the grid should revert to the default sort order if sorting is
set to "~".  Either that the grid should at least not remove any ordering on the IQueryable if sorting is
set to "~" -- then you could at least work around the problem by preordering the IQueryable before passing
it to the grid.

Cannot find a public property of primitive type to sort by.

[NotSupportedException: Cannot find a public property of primitive type to sort by.]
   Telerik.Web.Mvc.Extensions.TypeExtensions.FirstSortableProperty(Type type) in f:\115\Griffin\Trunk Full\Sources\Source\Telerik.Web.Mvc\Extensions\TypeExtensions.cs:59
   Telerik.Web.Mvc.Extensions.QueryableExtensions.ToGridModel(IQueryable queryable, Int32 page, Int32 pageSize, IList`1 sortDescriptors, IEnumerable`1 filterDescriptors, IEnumerable`1 groupDescriptors) in f:\115\Griffin\Trunk Full\Sources\Source\Telerik.Web.Mvc\Extensions\QueryableExtensions.cs:95
   Telerik.Web.Mvc.UI.GridDataProcessor.EnsureDataSourceIsProcessed() in f:\115\Griffin\Trunk Full\Sources\Source\Telerik.Web.Mvc\UI\Grid\GridDataProcessor.cs:247
   Telerik.Web.Mvc.UI.Grid`1.CreateRenderingData() in f:\115\Griffin\Trunk Full\Sources\Source\Telerik.Web.Mvc\UI\Grid\Grid.cs:796
   Telerik.Web.Mvc.UI.Grid`1.WriteHtml(HtmlTextWriter writer) in f:\115\Griffin\Trunk Full\Sources\Source\Telerik.Web.Mvc\UI\Grid\Grid.cs:672
   Telerik.Web.Mvc.UI.ViewComponentBase.ToHtmlString() in f:\115\Griffin\Trunk Full\Sources\Source\Telerik.Web.Mvc\UI\ViewComponentBase.cs:216
   Telerik.Web.Mvc.UI.ViewComponentBuilderBase`2.ToHtmlString() in f:\115\Griffin\Trunk Full\Sources\Source\Telerik.Web.Mvc\UI\ViewComponentBuilderBase.cs:154
   System.Web.WebPages.WebPageExecutingBase.WriteTo(TextWriter writer, Object content) +58
   ASP._Page_Views_Customers__CustomerList_cshtml.Execute() in c:\Users\Bruce\Documents\Beanstalk\PRISM10\Inovaware.PRISM.UI\Inovaware.PRISM.UI\Views\Customers\_CustomerList.cshtml:11
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +280
   System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +104
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +196
   System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName, Object model, ViewDataDictionary viewData) +158
   ASP._Page_Views_Customers_Index_cshtml.Execute() in c:\Users\Bruce\Documents\Beanstalk\PRISM10\Inovaware.PRISM.UI\Inovaware.PRISM.UI\Views\Customers\Index.cshtml:9
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +280
   System.Web.Mvc.WebViewPage.ExecutePageHierarchy() +104
   System.Web.WebPages.StartPage.ExecutePageHierarchy() +143
   System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +181
   System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +384
   System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +33
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +848388
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +848388
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +265
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +847456
   System.Web.Mvc.Controller.ExecuteCore() +159
   System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +335
   System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +62
   System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +20
   System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +54
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +469
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +375

 

 

Tags
Grid
Asked by
Bruce
Top achievements
Rank 1
Share this question
or