I'm assuming q_data
is a standard postgres query, in which the results of your query look like this (you can see this in Slate if you click the </>
button in the Query results preview panel):
{
id_pk: ["a", "c", "b"],
str_name_last_first: ["name1", "name2", "name3"]
}
You almost certainly want to implement sorting as part of the query rather than sorting with a Slate javascript function, which does the "work" of sorting in browser memory. In that case, you simply add an ORDER BY
statement to your SQL query.
If, for some reason, you really do need to do some sorting in a Slate javascript function, then with this data structure the easiest approach is to:
- Covert the single object with parallel lists of values (column structure) to a single list with key/value pairs for each column (row structure).
- Sort the list of objects
- Convert the list of objects back to a parallel columns data structure.
The Slate documentation has some example implementation of the conversion between these two commonly used formats for representing tabular data: https://www.palantir.com/docs/foundry/slate/references-convert-rows-columns/