[Bug-2737] Perspective table - sorting date column

In the long run, we used something similar to this as a transform on our dataset binding, so the table is pre-sorted by dates:

def sort_dataset_by_date(dset, date_column, ascending=True):
	orig_columns = system.dataset.getColumnHeaders(dset)
	tstamps = [system.date.toMillis(x) for x in dset.getColumnAsList(date_column)]
	dset = system.dataset.addColumn(dset, 0, tstamps, 'tmp_tstamp', long)
	dset = system.dataset.sort(dset, 0, ascending)
	return system.dataset.filterColumns(dset, orig_columns)

If you’re using this for a table component, you can leave the tmp_stamp column in place and just not display it.

2 Likes