{"id": 309471814, "node_id": "MDU6SXNzdWUzMDk0NzE4MTQ=", "number": 189, "title": "Ability to sort (and paginate) by column", "user": {"value": 9599, "label": "simonw"}, "state": "closed", "locked": 0, "assignee": {"value": 9599, "label": "simonw"}, "milestone": null, "comments": 31, "created_at": "2018-03-28T18:04:51Z", "updated_at": "2018-04-15T18:54:22Z", "closed_at": "2018-04-09T05:16:02Z", "author_association": "OWNER", "pull_request": null, "body": "As requested in https://github.com/simonw/datasette/issues/185#issuecomment-376614973\r\n\r\nI've previously avoided this for performance reasons: sort-by-column on a column without an index is likely to perform badly for hundreds of thousands of rows.\r\n\r\nThat's not a good enough reason to avoid the feature entirely though. A few options:\r\n\r\n* Allow sort-by-column by default, give users the option to disable it for specific tables/columns\r\n* Disallow sort-by-column by default, give users option (probably in `metadata.json`) to enable it for specific tables/columns\r\n* Automatically detect if a column either has an index on it OR a table has less than X rows in it\r\n\r\nWe already have the mechanism in place to cut off SQL queries that take more than X seconds, so if someone DOES try to sort by a column that's too expensive it won't actually hurt anything - but it would be nice to not show people a \"sort\" option which is guaranteed to throw a timeout error.\r\n\r\nThe vast majority of datasette usage that I've seen so far is on smaller datasets where the performance penalties of sort-by-column are extremely unlikely to show up.\r\n\r\n----\r\n\r\nStill left to do:\r\n\r\n- [x] UI that shows which sort order is currently being applied (in HTML and in JSON)\r\n- [x] UI for applying a sort order (with rel=nofollow to avoid Google crawling it)\r\n- [x] Sort column names should be escaped correctly in generated SQL\r\n- [x] Validation that the selected sort order is a valid column\r\n- [x] Throw error if user attempts to apply _sort AND _sort_desc at the same time\r\n- [x] Ability to disable sorting (or sort only for specific columns) in metadata.json\r\n- [x] Fix \"201 rows where sorted by sortable_with_nulls \" bug\r\n", "repo": {"value": 107914493, "label": "datasette"}, "type": "issue", "active_lock_reason": null, "performed_via_github_app": null, "reactions": "{\"url\": \"https://api.github.com/repos/simonw/datasette/issues/189/reactions\", \"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "draft": null, "state_reason": "completed"}