Sort Datatable order by

Hi all,

i need to sort datatable like this:

image

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

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,“[1]+$”).OrderBy(Function(r) r(0). ToString)).Concat(dt.AsEnumerable.Where(Function(r) System.Text.RegularExpressions.Regex.IsMatch(r(0).ToString,“[2]+$”)).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


  1. 0-9A-Za-z ↩︎

  2. A-Za-z ↩︎

Hello.

Try this:

yourDatatable.AsEnumerable.OrderBy(Function(x) x(“yourcolumnName”)).CopyToDataTable

Hug

Hi,

Can you try the following sample? This might be a little inefficient, but works.

image

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,

Hello @Yoichi,

I have a slight update from the initial query

image

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