✅ Sorting nested
So I've got this data model that looks something like this (some parts of the fields have been omitted as they are irrelevant)
I'm probably thinking too hard here and that's why I'm missing something simple, so I came here for help
I want to do the following in my component:
I've got a
List<UserMonth>
in my component, and I want to render a table by week.
The user selects a month and a year they wish to view, and I am supposed to find the UserMonth that was selected (List<UserMonth>.Select(x => x.Month == SelectedMonth && x.Year == SelectedYear)
.. should be easy enough)
Then I need to seperate the List<DaysWorked>
into a nested list: List<List<DaysWorked>>
where I sort each week's dates in its own list, and add that list to the list (but keep it sorted?) (Or if there is a better way I'd love to hear it)
and then I have to render basically for each week, its own table
So does anyone have any ideas on how to do this?10 Replies
I basically gotten so far as to make a Trunk method:
Now I only have to figure out when the first date of the week starts, and make the first list somewhere between 1 and 7 based on when the date starts in the week (DayOfWeek?)
and then create a new list of 7 for each other item I have in the trunk..
Then I hope I can render that seperately?
you can use Linq
GroupBy
and Calendar.GeWeekOfYear
Cyberrex#8052
REPL Result: Success
Console Output
Compile: 754.215ms | Execution: 104.603ms | React with ❌ to remove this embed.
Hrm, that's an interesting one. Let's see if I can replicate with what I have
Wait so the "Key" part of IGrouping in this case,
is that the int of the week or the index of the item?
its what it groups by
in this case the number of week of year, yes
okay, so if I select November as selectedMonth (aka int 10)
do I then still get
IGrouping<int, DaysWorked>.Key
to be starting at 0, or does it actually start at the week number of that month?
trying to figure out because of this:
where I'm trying to figure out what to make of Week #@(list)
.. should this be list.Key
or should it be somethig else to get the actual weeknumber of the year of the currently selected month
but I guess I'll try it out, once I get the project to build 😅week number of the whole year
so the first week of november would be
Cyberrex#8052
REPL Result: Success
Result: int
Compile: 432.284ms | Execution: 24.594ms | React with ❌ to remove this embed.
so 39th week of the year
Awesome, thanks!
I'm testing it now
You sir, are my hero of today!
Thanks so much! It works wonders 😁