Custom Sorting of GridView with DataPager

5 posts, 0 answers
  1. gureumi
    gureumi avatar
    24 posts
    Member since:
    Dec 2008

    Posted 03 Feb 2011 Link to this post


    private
    void gridView_Sorting(object sender, GridViewSortingEventArgs e)
     {
        try
        {
           if (schedules == null)
           {
              e.Cancel = true;
              return;
           }
     
     
           if (e.OldSortingState == SortingState.Ascending)
           {
              e.NewSortingState = SortingState.Descending;
              schedules = schedules.OrderByDescending(s => s.Role).ThenBy(s => s.Name).ToList();
           }
           else if (e.OldSortingState == SortingState.Descending)
           {
              schedules = schedules.OrderByDescending(s => s.Name).ToList();
              e.NewSortingState = SortingState.None;
           }
           else
           {
              e.NewSortingState = SortingState.Ascending;
              schedules = schedules.OrderBy(s => s.Role).ThenBy(s => s.Name).ToList();
           }
           this.radDataPager.Source = schedules;
           //e.DataControl.ItemsSource = this.radDataPager.Source;  // replaced by the next line which is the same thing.
           this.gridView.ItemsSource = this.radDataPager.Source;
           this.gridView.Items.Refresh();
     
           this.radDataPager.PageIndex = 0;
           e.Cancel = true;
        }
        catch (Exception ex)
        {
           txtStatus.Text = "Erorr in gridView_Sorting:"+ex.Message;
        }
     }
    Custom Sorting (routine shown above) of GridView with DataPager does not seem to work.
    It shows sorted items on the current page but it does not navigate to another page.

    Can you provide small sample code that works?

    Thanks.
  2. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 07 Feb 2011 Link to this post

    Hi gureumi,

    We could not quite understand the exact goal that you are after. What page should it navigate to?

    We see that you are explicitly making the pager go to the first page by doing this:

    this.radDataPager.PageIndex = 0;

    Do you mean that it does not go to the first page? Could you please elaborate?

    Thanks in advance.

    Kind regards,
    Ross
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
  3. UI for WPF is Visual Studio 2017 Ready
  4. gureumi
    gureumi avatar
    24 posts
    Member since:
    Dec 2008

    Posted 07 Feb 2011 Link to this post

    I tried that already.

    Simple symptom is it does not move to the next page or any other page.
  5. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 07 Feb 2011 Link to this post

    Hi gureumi,

    Have you tried binding the gridview to the PagedSource property of RadDataPager?

    Best wishes,
    Veselin Vasilev
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
  6. gureumi
    gureumi avatar
    24 posts
    Member since:
    Dec 2008

    Posted 07 Feb 2011 Link to this post

    Thanks.

    You found the problem.

    In the Loaded routine 

    I had the following.
                this.radDataPager.Source = schedules;
                this.gridView.ItemsSource = this.radDataPager.PagedSource;
                this.gridView.Items.Refresh();


                this.radDataPager.PageIndex = 0;

    But the code shown above had this.radDataPager.Source instead of PagedSource.

    My stupid mistake. Thanks again...
Back to Top
UI for WPF is Visual Studio 2017 Ready