Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sorting a Data Table

Tags:

.net

vb.net

I tried to sort a data table with following two ways

table.DefaultView.Sort = "Town ASC, Cutomer ASC"  table.Select("", "Town ASC, Cutomer ASC") 

But none of them wasn't worked. It always displays data in original order. Do you have any idea to solve the problem.

like image 941
pasanmaduranga Avatar asked Sep 18 '12 08:09

pasanmaduranga


People also ask

What is sorting in table?

Sorting allows the user to reorder rows by the contents of a column. This is a live continuous sort , and new rows that get added or rows that get edited will be resorted immediately after, and you will not be able to manually reorder rows. You can sort on multiple columns with multiple sort directions.

How do I sort a data table in R?

To sort a data frame in R, use the order( ) function. By default, sorting is ASCENDING. Prepend the sorting variable by a minus sign to indicate DESCENDING order.

Can you sort a table in Excel?

To sort a table in Excel by a single column, click into a cell within the column by which to sort the data. To sort the table in either ascending or descending order by the column's data values, click either the “Sort A to Z” or “Sort Z to A” buttons in the “Sort & Filter” button group on the “Data” tab in the Ribbon.


2 Answers

This was the shortest way I could find to sort a DataTable without having to create any new variables.

DataTable.DefaultView.Sort = "ColumnName ASC" DataTable = DataTable.DefaultView.ToTable 

Where:

ASC - Ascending

DESC - Descending

ColumnName - The column you want to sort by

DataTable - The table you want to sort

like image 195
djalonsoc Avatar answered Oct 02 '22 08:10

djalonsoc


Try this:

Dim dataView As New DataView(table) dataView.Sort = " AutoID DESC, Name DESC" Dim dataTable AS DataTable = dataView.ToTable() 
like image 26
Kapil Khandelwal Avatar answered Oct 02 '22 07:10

Kapil Khandelwal