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

Datasource sorting not retained

14 Answers 98 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Marbry
Top achievements
Rank 1
Marbry asked on 11 Mar 2013, 04:24 PM
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.

14 Answers, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 14 Mar 2013, 01:01 PM
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.
0
Marbry
Top achievements
Rank 1
answered on 14 Mar 2013, 01:47 PM
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.

0
Plamen
Telerik team
answered on 18 Mar 2013, 12:01 PM
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.
0
Marbry
Top achievements
Rank 1
answered on 18 Mar 2013, 04:00 PM
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.
0
Plamen
Telerik team
answered on 20 Mar 2013, 07:20 AM
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.
0
Marbry
Top achievements
Rank 1
answered on 20 Mar 2013, 01:03 PM
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.

0
Plamen
Telerik team
answered on 25 Mar 2013, 01:40 PM
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.
0
Marbry
Top achievements
Rank 1
answered on 25 Mar 2013, 03:51 PM
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?
0
Plamen
Telerik team
answered on 28 Mar 2013, 12:17 PM
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.
0
Marbry
Top achievements
Rank 1
answered on 28 Mar 2013, 12:41 PM
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.
0
Plamen
Telerik team
answered on 28 Mar 2013, 02:28 PM
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.
0
Marbry
Top achievements
Rank 1
answered on 29 Mar 2013, 04:28 PM
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.
0
Plamen
Telerik team
answered on 03 Apr 2013, 01:00 PM
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.
0
Marbry
Top achievements
Rank 1
answered on 09 May 2013, 01:02 PM
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.
Tags
Scheduler
Asked by
Marbry
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Marbry
Top achievements
Rank 1
Share this question
or