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
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.
Plamen
the Telerik team
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.
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.
Plamen
the Telerik team
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.
Plamen
the Telerik team
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.
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
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?
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.
Plamen
the Telerik team
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.
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.
Plamen
the Telerik team
Since I have a complex header, I'm dependent on that event to write the header content into the appropriate location when that fires.
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
It worked as intended after this.