Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WPF > DataPager > Custom Sorting of GridView with DataPager

Not answered Custom Sorting of GridView with DataPager

Feed from this thread
  • gureumi avatar

    Posted on Feb 3, 2011 (permalink)


    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.

    Reply

  • Rossen Hristov Rossen Hristov admin's avatar

    Posted on Feb 7, 2011 (permalink)

    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>>

    Reply

  • gureumi avatar

    Posted on Feb 7, 2011 (permalink)

    I tried that already.

    Simple symptom is it does not move to the next page or any other page.

    Reply

  • Veselin Vasilev Veselin Vasilev admin's avatar

    Posted on Feb 7, 2011 (permalink)

    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>>

    Reply

  • gureumi avatar

    Posted on Feb 7, 2011 (permalink)

    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...

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / WPF > DataPager > Custom Sorting of GridView with DataPager