Code for getting a sorted version of a table


Details

Shows how to use a TableSort to get descendingly sorted data.


Original author/s: Andy Evans
Original location/s:
Adapted by:
License: none


Imports and instance variables

	import com.esri.arcgis.geodatabase.*;
	import javax.swing.*;
	
	private ITable table = someTable; // Got from somewhere.

Code

	ITableSort tableSort = new TableSort();
	tableSort.setTableByRef(table);
	tableSort.setFields("COLUMN_NAME");
	tableSort.setAscending("COLUMN_NAME", false); // Use true for ascending sort.
	tableSort.sort(null);
	ICursor iCursor = tableSort.getRows();
	
	IRow row = iCursor.nextRow();
	String results = "";
		
	int fieldIndex = row.getFields().findField("COLUMN_TO_PRINT");
		
	while (row != null) {
		results = results + row.getValue(fieldIndex) + "\n";
		row = iCursor.nextRow();
	}
	JOptionPane.showMessageDialog(null, results);