How do you sort a dataset

Hi,
I am collecting data from various Lines and Machines and storing it in multiple tables. I often want to display this data on a window using a table where the column headings of the database table are in one column of a dataset and the value is in the next column. Basically I want to turn the table on it’s side.

I have the following function in a module that I call when I need to do this. This is working very well but I would like to sort the column names.

I would like to either sort by column name at the query definition or within the function. Is there a simple way to do this?

def turnTableSideways(ds): import fpmi headers = [] for c in range(ds.getColumnCount()): headers.append(ds.getColumnName(c)) pyNewData = [] pyOldData = fpmi.dataset.toPyDataSet(ds) for x in range(len(headers)): strDetail = str(pyOldData[0][x]) pyNewData.append([headers[x],strDetail]) dsSideways = fpmi.dataset.toDataSet(["Item","Value"],pyNewData) return dsSideways
Thanks,

Sorry, I should have searched the net for this first.

I added pyNewData.sort() to the existing code.

def turnTableSideways(ds): import fpmi headers = [] for c in range(ds.getColumnCount()): headers.append(ds.getColumnName(c)) pyNewData = [] pyOldData = fpmi.dataset.toPyDataSet(ds) for x in range(len(headers)): strDetail = str(pyOldData[0][x]) pyNewData.append([headers[x],strDetail]) pyNewData.sort() dsSideways = fpmi.dataset.toDataSet(["Item","Value"],pyNewData) return dsSideways

1 Like

Glad you got it working.

For what its worth, I would like to add a rotateDataset() and sortDataset() function to the system.dataset library.

1 Like