Issue with sorting SPDataSource from RadGrid

7 posts, 0 answers
  1. rh
    rh avatar
    193 posts
    Member since:
    Jan 2007

    Posted 02 Jun 2009 Link to this post

    When I sort a RadGrid that is bound to an SPDataSource I get the following error:

    One or more field types are not installed properly. Go to the list settings page to delete these fields.


    When I look at the SharePoint logs I notice that the select command contains an order by clause that is presumably somehow being added by RadGrid because it is nowhere in my code and this is the collumn that I clicked on.

    <OrderBy><FieldRef Name="Process2 ASC" Ascending="TRUE"></FieldRef></OrderBy> 

    Notice that the FieldRef in the order by clause has a name of "Process2 ASC". It is my assumption that the "ASC" in the field name is causing the issue. How do I get it to not include the ASC in the field name in the order by?

    I tried updating the SortExpression in the SortCommand event of the grid but SortExpression is a read only property. I'm not too sure what else to do.

    protected

     

    void _grid_SortCommand(object source, GridSortCommandEventArgs e)

     

    {

    e.SortExpression = e.SortExpression.Replace(

    " ASC", String.Empty);

     

    e.SortExpression = e.SortExpression.Replace(

    " DESC", String.Empty);

     

    }

  2. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 03 Jun 2009 Link to this post

    Hello rh,

    Can you please check whether the same issue appears when you replace temporary the RadGrid instance with regular MS GridView? Additionally, note that you can control the sorting modes manually intercepting the SortCommand event of the grid and canceling the default sort operation as illustrated in this topic from the documentation. This should help you apply the sort criteria and avoid the exception.

    Kind regards,
    Sebastian
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.

  3. rh
    rh avatar
    193 posts
    Member since:
    Jan 2007

    Posted 03 Jun 2009 Link to this post

    I've looked at the SortCommand event but fail to see how it will help for a number of reasons:

    1. The GridSortExpression needs a field name but the GridSortCommandEventArgs doesn't provide the field name.
    2. All you can really do with the GridSortExpression is set the FieldName and the SortOrder. I fail to see how this is going to prevent the ASC keyword from being put in the FieldRef name.

    The ASP.NET GridView does not generate the error below when sorting. That's the good news. The bad news is that it doesn't sort. It just refreshes the page without doing anything.

  4. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 04 Jun 2009 Link to this post

    Hello rh,

    You can traverse the SortExpressions collection of the respective GridTableView as illustrates in the code example from the documentation topic and modify the FieldName passed from the FieldRef (Process2 ASC) to remove the ASC part. Thus you should be able to avoid the error/unexpected result you saw in the same scenario with the MS GridView.

    Additionally, you can specify the sort order manually if you would like to. Keep in mind that you need to cancel the default action first and rebind the grid explicitly at the end of the SortCommand handler.

    Kind regards,
    Sebastian
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  5. Elad
    Elad avatar
    13 posts
    Member since:
    Jan 2009

    Posted 19 Jul 2009 Link to this post

    Hi,
    I am having the exact same issue.
    I have tried what you suggested, but it doesn't work.
    To make the problem more clear I run the following test:

    In the Sort Event handler, I set the FieldName property of the sort expression to a constant string - "MyTest". This is not one of my fields, it's just a string that i can recognize later.
    Then, I run the app, get the same error, and in the log files I see that the query was:
    <OrderBy><FieldRef Name="MyTest ASC" Ascending="True"></FieldRef></OrderBy>
    So radGrid appends the sort expression to the field name even if I manually set the field name!

    Any suggestions?

    Thanks,
    Elad.
  6. rh
    rh avatar
    193 posts
    Member since:
    Jan 2007

    Posted 19 Jul 2009 Link to this post

    I agree. I wish Telerik would take the time to recreate the problem and try to implement their suggested solution themselves. If they find that it works that would be great and they can post the solution in more detail. However, I think they may find that it doesn't work.

    I gave up trying to use the RadGrid in SharePoint because of this issue and went back to using the SPGridView.
  7. Sebastian
    Admin
    Sebastian avatar
    9934 posts

    Posted 21 Jul 2009 Link to this post

    Hello guys,

    In order to workaround the issue with the way SPDataSource handles sorting, you will need to handle the sorting manually as explained previously in my reply or as shown in this help article.

    Kind regards,
    Sebastian
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Back to Top