0

Need to order a datatable by partial condition. Have a datatable in this way:

[0]: P01,10,01; 
[1]: P01,10,02;
     ... 
[n]: P03,10,01;
     ... 
[m]: P03,10,02;

What I need to do is ordering the datatable by a partial portion of data; Example: When first row is odd it must be in descending order, while a pair must by in ascending. The value returned must look like:

[0]: P02,10,01; 
[1]: P02,10,02;
     ... 
[n]: P03,10,03;
     ... 
[m]: P03,10,02;

I know that a sort in datatable and default dataview can do that.
How can I sort this data in a datatable?

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • 2
    Your sorting criteria make no sense. What does "When first row is odd" mean? Can you give a more complete example, with an explanation? – Jim Mischel Apr 23 '13 at 14:25
  • Means: when Pxx where xx is odd the order must be descending. So: P02 must be ascending; P03 must be descending – Gaston Santos Apr 23 '13 at 14:29
  • As far as I know, you can't sort a `DataTable` directly. You can create a `DataView`, sort it, and create a new `DataTable`, as shown in http://stackoverflow.com/a/9108171/56778. But it doesn't look like you can specify sorting criteria that will do what you want. – Jim Mischel Apr 23 '13 at 15:00
  • Yes, by this way you can sort a datatable: dt.Select("ROW TO FILTER= 'VALUE TO FILTER'", "COLUMN DESC"). The value dt is passing by as a datatable parameter, and the COLUMN is the order by – Gaston Santos Apr 23 '13 at 15:08
  • So you're not wanting to sort the table in-place, but rather to sort the results returned from a `Select`. Nevertheless, I don't think the expression syntax is sufficiently expressive for your needs. – Jim Mischel Apr 23 '13 at 16:12
  • I could do in-place or even in a returned value, but i want to know the more eficient way to do it – Gaston Santos Apr 23 '13 at 16:18

0 Answers0