Sort table based on a given field

516
2
Jump to solution
05-24-2023 02:01 PM
KisakyeM
New Contributor III

How can one programmatically sort a table on a given field? This functionality is achieved in Pro by the user right clicking on a given field and electing to sort descending or ascending on that field. Is this attainable using the pro sdk?

@UmaHarano @CharlesMacleod @Wolf 

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
Wolf
by Esri Regular Contributor
Esri Regular Contributor

Starting with Release 3.1, you can use the TableView class as described here:  ProConcepts Map Exploration · Esri/arcgis-pro-sdk Wiki (github.com)

and specifically the SortAscending Method:  SortAscending Method (TableView)—ArcGIS Pro

The code would look like this:

 

var tv = TableView.Active;
if (tv == null)
  return;

// sort the active field descending
if (tv.CanSortDescending)
  tv.SortDescending();


// sort the active field ascending
if (tv.CanSortAscending)
  tv.SortAscending();


// peform a custom sort programmatically
if (tv.CanCustomSort)
{
  // sort fields
  var dict = new Dictionary<string, FieldSortInfo>();
  dict.Add("STATE_NAME", FieldSortInfo.Asc);
  dict.Add("CITY_NAME", FieldSortInfo.Desc);
  await tv.SortAsync(dict);
}


// perform a custom sort via the UI
if (tv.CanCustomSort)
  tv.CustomSort();

 

View solution in original post

2 Replies
Wolf
by Esri Regular Contributor
Esri Regular Contributor

Starting with Release 3.1, you can use the TableView class as described here:  ProConcepts Map Exploration · Esri/arcgis-pro-sdk Wiki (github.com)

and specifically the SortAscending Method:  SortAscending Method (TableView)—ArcGIS Pro

The code would look like this:

 

var tv = TableView.Active;
if (tv == null)
  return;

// sort the active field descending
if (tv.CanSortDescending)
  tv.SortDescending();


// sort the active field ascending
if (tv.CanSortAscending)
  tv.SortAscending();


// peform a custom sort programmatically
if (tv.CanCustomSort)
{
  // sort fields
  var dict = new Dictionary<string, FieldSortInfo>();
  dict.Add("STATE_NAME", FieldSortInfo.Asc);
  dict.Add("CITY_NAME", FieldSortInfo.Desc);
  await tv.SortAsync(dict);
}


// perform a custom sort via the UI
if (tv.CanCustomSort)
  tv.CustomSort();

 

Wolf
by Esri Regular Contributor
Esri Regular Contributor

You can also search for the videos from Dev Summit 2023 specifically the session:

"Intermediate Data Visualization Using Table Controls"

You can find the session resources here:  Tech Sessions · Esri/arcgis-pro-sdk Wiki (github.com)