New Table component sorting by column not working

I have a new table component that is set to use pagination. My query grabs 50 records at a time and the table is set to a size to view only about 20 rows and the user can scroll to view the rest of the 50 and then use the pagination buttons to get the next page of rows. This works fine.

However, the sorting functionality is now not working. The visuals are there - I see the little arrow indicating the sort direction change, but the table is not sorted. Is this a known bug?

Hi Barry! With server-side paginated tables (as your table seems to be set up), it's best to apply server-side sorting -- I'm guessing you want to sort your entire data set instead of just the page.

You can do this by accessing the sortArray property on the table to get the currently table's active sort (indicated via headers), and then use that property in your query to sort the data.

image

If your resource has prepared statements disabled, you can reference these directly in your query like so:

SELECT * FROM example_table ORDER BY {{table1.sortArray[0].columnId}} {{table1.sortArray[0].direction}} ...

This forum post also has information on dynamically setting sort with prepared statements on.

More features will be coming soon that help with configuring both client-side and server-side sorting on tables. Hope this helps!

1 Like

What's the reasoning behind not allowing client side sorting when using server-side pagination? All the examples given when talking about server side pagination makes "sense" when talking about sql databases. But using for example Dynamo this might be more complex. It's definitely not a reasonable thing to assume that a dynamo query can be made efficiently for all columns in the dataset. Would have been great if it was still possible to have client side sorting whilst using server side pagination.

1 Like

Thanks for the feedback, @Lewenhaupt! There may be multiple reasons, but I know we've gotten feedback in the past that if there's client side sorting, it's not necessarily clear that it would only sort one page of the dataset. Not sorting client side nudges builders to consider implementing server side sorting