Sort order of resource
How would we determine the sort order of listed resources in scheduler? They appear to sort automatically based on a string so anything ending in numbers is incorrectly ordered, see image:
The Desk is numbered 1-20 but due to string sort it goes from desk 1 then 10,11 etc.. to 19 then back to desk 2.
Thanks, Martin
Hi
Martin Holmes,
Sample: https://blazorplayground.syncfusion.com/LjVziZVpnkUjzPeA
The Blazor Scheduler resources are rendered in the order you provided in the
resources list. To render the resources based on your requirement you must
arrange the resources list to your desired order before binding it to the
Scheduler. The example code below shows how to order the resources list based
on the number present in OwnerText field and bind it to the Scheduler.
[Index.razor]
|
<SfSchedule TValue="AppointmentData" Height="550px" @bind-SelectedDate="@CurrentDate"> <ScheduleResources> <ScheduleResource TItem="ResourceData" TValue="int[]" DataSource="@OwnersData" Field="OwnerId" Title="Owner" Name="Owners" TextField="OwnerText" IdField="Id" ColorField="OwnerColor" AllowMultiple="true"></ScheduleResource> </ScheduleResources> </SfSchedule> @code{ public List<ResourceData> OwnersData { get; set; } = new List<ResourceData> { new ResourceData{ OwnerText = "Desk 7", Id = 7 }, new ResourceData{ OwnerText = "Desk 8", Id = 8 }, new ResourceData{ OwnerText = "Desk 9", Id = 9 }, new ResourceData{ OwnerText = "Desk 10", Id = 10 }, new ResourceData{ OwnerText = "Desk 11", Id = 11 }, new ResourceData{ OwnerText = "Desk 12", Id = 12 }, new ResourceData{ OwnerText = "Desk 1", Id = 1 }, new ResourceData{ OwnerText = "Desk 2", Id = 2 }, new ResourceData{ OwnerText = "Desk 3", Id = 3 }, new ResourceData{ OwnerText = "Desk 4", Id = 4 }, new ResourceData{ OwnerText = "Desk 5", Id = 5 }, new ResourceData{ OwnerText = "Desk 6", Id = 6 }, };
protected override void OnInitialized() { OrderOwnersData(); }
public void OrderOwnersData() { OwnersData = OwnersData.OrderBy(o => ExtractNumber(o.OwnerText)).ToList(); }
private int ExtractNumber(string ownerText) { // Extract the numeric part from the OwnerText var match = System.Text.RegularExpressions.Regex.Match(ownerText, @"\d+"); return match.Success ? int.Parse(match.Value) : 0; } } |
Regards,
Ravikumar Venkatesan
- 1 Reply
- 2 Participants
-
MH Martin Holmes
- Oct 23, 2024 10:05 AM UTC
- Oct 24, 2024 07:28 PM UTC