Kumar802
(Kumar802)
July 11, 2022, 8:47am
1
Hi all,
i need to sort datatable like this:
on the left the original table, and on the right the sorting I would like to give.
so, at the top all those containing alphanumeric characters beginning with a letter, then alphanumeric characters beginning with a number.
Thanks in advance
Hey!
Have you tried with SortDataTable with Ascending order?
Regards,
NaNi
Hey
Use this flow diagram
you can use sort data table
you can make change Order property it Acending or decending
Thanks,
Rounak
Kumar802
(Kumar802)
July 11, 2022, 9:04am
4
non funziona utilizzando l’attività sort datatable, ho utilizzato questa query:
dt = dt.AsEnumerable.Where(Function(r) System.Text.RegularExpressions.Regex.IsMatch(r(0).ToString,“^\d+$”)).OrderBy(Function(r) Double. Parse(r(0).ToString)).Concat(dt.AsEnumerable.Where(Function(r) System.Text.RegularExpressions.Regex.IsMatch(r(0).ToString,“[A-Za-z]”) AndAlso System.Text.RegularExpressions.Regex.IsMatch(r(0).ToString,“\d”) AndAlso System.Text.RegularExpressions.Regex.IsMatch(r(0).ToString,“+$”).OrderBy(Function(r) r(0). ToString)).Concat(dt.AsEnumerable.Where(Function(r) System.Text.RegularExpressions.Regex.IsMatch(r(0).ToString,“+$”)).OrderBy(Function(r) r(0).ToString)).CopyToDataTable
recommended by @Yoichi and it works but the parameters I had provided were not correct, so I should revise the regexes
Hello.
Try this:
yourDatatable.AsEnumerable.OrderBy(Function(x) x(“yourcolumnName”)).CopyToDataTable
Hug
Yoichi
(Yoichi)
July 11, 2022, 9:18am
6
Hi,
Can you try the following sample? This might be a little inefficient, but works.
dt =dt.AsEnumerable.Where(Function(r) not Int32.TryParse(System.Text.RegularExpressions.Regex.Match(r(0).ToString,"^\d+").Value,New Int32)).OrderBy(Function(r) r(0).ToString).Concat(dt.AsEnumerable.Where(Function(r) Int32.TryParse(System.Text.RegularExpressions.Regex.Match(r(0).ToString,"^\d+").Value,New Int32)).OrderBy(Function(r) Int32.Parse(System.Text.RegularExpressions.Regex.Match(r(0).ToString,"^\d+").Value)).ThenBy(Function(r) System.Text.RegularExpressions.Regex.Match(r(0).ToString,"(?<=\d+).*").Value)).CopyToDataTable
Sample20220711-4.zip (2.8 KB)
Regards,
Kumar802
(Kumar802)
November 9, 2022, 2:29pm
7
Hello @Yoichi ,
I have a slight update from the initial query
we need to sort them based on the first 3 characters, as you see in the new file 308 is after 3038, while with the initial query it would have gone first 308 and then 3038, could you help me modify the query?
Thanks in advance