Datasource sorting not retained

15 posts, 0 answers
  1. Marbry
    Marbry avatar
    123 posts
    Member since:
    Aug 2012

    Posted 11 Mar 2013 Link to this post

    Shouldn't the scheduler retain the sorting of the datasource that's bound to it?

    It does not seem to be doing this.  I sort a list, bind it to to the scheduler resource types, and it appears to ignore the order of items in the list.

    I have about 7 columns in the resources, so it's important for the user to be able to sort those.
  2. Plamen
    Admin
    Plamen avatar
    3079 posts

    Posted 14 Mar 2013 Link to this post

    Hi Marbry,

     
    Thank you for contacting Telerik support.

    I have tested the scenario you described by changing using order by command when selecting resources and they displayed as expected. I am attaching a sample test web page where the affected resource is "Users". Please review it and let me know if you have further questions or your scenario is somehow different. 

    Kind regards,
    Plamen
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. Marbry
    Marbry avatar
    123 posts
    Member since:
    Aug 2012

    Posted 14 Mar 2013 Link to this post

    That's a bit different from my implementation.  On page init I'm calling a refresh function that queries the DB, retrieves the results into a list, then sorts that list based on what the user has selected to sort by, then uses that list as the datasource for the scheduler.

    Retrieve the data into the list "result".

    Order by the field list "names".
    result = (from r in result
               where r.AppointmentID != 0
               select r).OrderBy(names).ToList();


    Set the scheduler DataSource equal to "result".


    Pare the data down to a distinct set based on the fields that make up the resource.
    newResult = (from r in result
        select r).Distinct(new Utility.AppointmentDataEquals()).OrderBy(names).ToList();


    Set the scheduler resource types DataSource equal to the "newResult" list containing the distinct set of the resource fields values.
    scheduler.ResourceTypes[0].DataSource = newResult;
    scheduler.DataBind();


    So I can confirm that the lists as they are being set to the datasources are in the desired order.  But immediately after that as I write the headers out in the ResourceHeaderCreated event handler, they are not in the order that the lists were set to.

  4. Plamen
    Admin
    Plamen avatar
    3079 posts

    Posted 18 Mar 2013 Link to this post

    Hello Marbry,

     
    In such scenario instead of using DataSource property we recommend adding the Resources in the desired order one by one as it is done in this on-line demo.

    Hope this will be helpful.

    Kind regards,
    Plamen
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  5. Marbry
    Marbry avatar
    123 posts
    Member since:
    Aug 2012

    Posted 18 Mar 2013 Link to this post

    I'm afraid that exhibits the same problem.  The ResourceHeaderCreated event does not fire in the same order that the resources are added.  And I'm adding most of the resource content to the ResourceHeaderTemplate in that handler.
  6. Plamen
    Admin
    Plamen avatar
    3079 posts

    Posted 20 Mar 2013 Link to this post

    Hi Marbry,

     
    It seems that there is some kind of misunderstanding -please excuse me for that. What I meant in my previous reply is to change the order of adding the resources-here is a video of the test that I made at my side that worked properly. Please review it and let me know if I am not testing properly or if the scenario is somehow different.

    Regards,
    Plamen
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  7. Marbry
    Marbry avatar
    123 posts
    Member since:
    Aug 2012

    Posted 20 Mar 2013 Link to this post

    I understood what you meant, and I see in the video that your example shows that, but it's not working that way for me.

    I tried iteratively adding the resources in the desired order, but even confirming that it is correct with the debug statement below they do not end up in that order.  The ResourceHeaderCreated event handler is not firing in the order the resources are in when they are added.
    private void LoadResources(List<GetResult> resources)
    {
    ResourceType resType = new ResourceType("Group");
    resType.ForeignKeyField = "CompositeKey";
    resType.TextField = "DisplayNames";
    resType.KeyField = "CompositeKey";
    resType.AllowMultipleValues = false;
     scheduler.ResourceTypes.Add(resType);
    for (int i = 0; i < resources.Count; i++)
    {
    //Debug.Print(resources[i].CompositeKey + Environment.NewLine);
     scheduler.Resources.Add(new Resource("Group", resources[i].CompositeKey, resources[i].DisplayNames));
    }
    }

    I'm using it in timeline view, grouped vertically.  The data has many appointments that are long in duration and span many time slots.

  8. Plamen
    Admin
    Plamen avatar
    3079 posts

    Posted 25 Mar 2013 Link to this post

    Hi Marbry,

     
    I have tested once again the same scenario with code similar to the one that you shared but it displayed properly once again:

    private void InitializeResources()
           {
               
               List<Resource> resources = new List<Resource> { new Resource("User", 2, "Bob"), new Resource("User", 3, "Charlie"), new Resource("User", 1, "Alex") };
               ResourceType resType = new ResourceType("User");
               resType.ForeignKeyField = "UserID";
               resType.TextField = "DisplayNames";
               resType.KeyField = "CompositeKey";
               resType.AllowMultipleValues = false;
               RadScheduler1.ResourceTypes.Add(resType);
               for (int i = 0; i < resources.Count; i++)
               {
                   RadScheduler1.Resources.Add(resources[i]);
               }
           }

    I am also attaching my test web page please let us know if your scenario is somehow different so we could be more helpful.

    Kind regards,
    Plamen
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  9. Marbry
    Marbry avatar
    123 posts
    Member since:
    Aug 2012

    Posted 25 Mar 2013 Link to this post

    I've narrowed the issue further.  If I set the order of resources on the initial load, it works as I expect.  When I try to do that subsequently in the same place (when the user clicks a column to sort by) it does not.  It retains the previous sorting regardless of how I alter the order of the list at that point.

    It appears to be retaining the initial sorting somehow.  I'm already calling scheduler.Resources.Clear()  and   scheduler.ResourceTypes.Clear()  when I reload the data.  Is there something else that needs to be reset?
  10. Plamen
    Admin
    Plamen avatar
    3079 posts

    Posted 28 Mar 2013 Link to this post

    Hello Marbry,

     
    In such cases when you want to change the order of grouping  somehow or the resources themselves we recommend achieving it the same way as it is done in this example here.

    Hope this will be helpful.

    Kind regards,
    Plamen
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  11. Marbry
    Marbry avatar
    123 posts
    Member since:
    Aug 2012

    Posted 28 Mar 2013 Link to this post

    Thenk you, but I don't see where that example is doing any sorting.  It only appears to be filtering them and I already have code working that does that.

    I need to be able to change the sorting of the current set of resources.  The problem is that it is somehow retaining the original sorting even when I reload the resources with a different order.
  12. Plamen
    Admin
    Plamen avatar
    3079 posts

    Posted 28 Mar 2013 Link to this post

    Hello Marbry,

     
    Please excuse me if I did not explain my self properly .What I meant is to use the RadScheduler1_DataBound event to remove the resources and add them in the appropriate order after that. I am attaching the updated project. 

    Hope this will be helpful. Please let me know if your case is somehow different again and this is not working for you.

    Regards,
    Plamen
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  13. Marbry
    Marbry avatar
    123 posts
    Member since:
    Aug 2012

    Posted 29 Mar 2013 Link to this post

    I tried this also, but the issue remains the same.  The ResourceHeaderCreated event handler is not firing in the order that the resources are added in when changing the sorting after initial load.  It's like that order is being cached somewhere.

    Since I have a complex header, I'm dependent on that event to write the header content into the appropriate location when that fires.
  14. Plamen
    Admin
    Plamen avatar
    3079 posts

    Posted 03 Apr 2013 Link to this post

    Hello Marbry,

     
    I have tested the scenario once again by adding the following code and it worked as expected again:

    <telerik:RadScheduler runat="server" ID="RadScheduler1" GroupBy="User" OnDataBound="RadScheduler1_DataBound"
          StartInsertingInAdvancedForm="true" StartEditingInAdvancedForm="true"  OnResourceHeaderCreated="RadScheduler1_ResourceHeaderCreated"   
          >
             <ResourceHeaderTemplate>
                 <telerik:RadTextBox runat="server" ></telerik:RadTextBox>
              </ResourceHeaderTemplate>
      </telerik:RadScheduler>
    protected void RadScheduler1_ResourceHeaderCreated(object sender, ResourceHeaderCreatedEventArgs e)
      {
          RadTextBox a = ((RadTextBox)e.Container.Controls[1]);
          a.Text = e.Container.Resource.Key.ToString();
      }

    Hope this will be helpful. Please let me know if you have further questions.

    Kind regards,
    Plamen
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  15. Marbry
    Marbry avatar
    123 posts
    Member since:
    Aug 2012

    Posted 09 May 2013 Link to this post

    After taking your code and trying to duplicate the behavior I finally discovered what the problem was.  I moved the calls to reload the resources and rebind the scheduler to the Page_Load handler from Page_Init.

    It worked as intended after this.
Back to Top