Sorting on a SUM() column of a Database Paged Query

Perhaps it wasn’t presented as a bug initially. This obviously happens when it’s not known if an issue is a bug or just not knowing how to use a feature. I think it should have been turned into a bug topic.

If you use Query Builder to create a query with aggregate columns and use this query with the table generator, including column sorting options, the sorting will fail for the aggregate columns - because an extra column is included. I would have thought this was a bug.

Could you create a new bug topic for this? It is the best way to go, otherwise bug report and tracking get lost in the noise of longer topics like this one.

I’ve created a new topic for this. For some reason, none of the Wappler team contributed to this thread, so it was never confirmed as a bug - at least I assume it is.

Just to make sure, the problem is that when you make the columns sortable with the table generator, sorting on the aggregate columns do fail. I don’t believe it was possible to order on the aggregate columns in the query builder, but the table generator is not aware of the aggregate columns and makes them sortable. Will see what we could improve.

btw. Which server model do you use, ASP/PHP or node?

Yes, that’s correct. Using the table generator, the sort headers appear as you would expect, and sort - it’s just that the sorting isn’t correct. Eg instead of:

ORDER BY  `count_total` DESC

the query includes:

ORDER BY `stock_id` DESC, `count_total` DESC`

This using PHP.

I have updated the sort, here the updated file. Place it in dmxConnectLib/modules.

dbconnector.zip (1.6 KB)

Update will also be included in today’s Wappler update.

1 Like

Great - I’ve just tested it and the issue is indeed fixed. Thanks.