New sortable_columns option in metadata.json to control sort options

You can now explicitly set which columns in a table can be used for sorting
using the _sort and _sort_desc arguments using metadata.json:

    {
        "databases": {
            "database1": {
                "tables": {
                    "example_table": {
                        "sortable_columns": [
                            "height",
                            "weight"
                        ]
                    }
                }
            }
        }
    }

Refs #189
This commit is contained in:
Simon Willison 2018-04-08 21:58:25 -07:00 committed by Simon Willison
commit b13f0986f2
7 changed files with 93 additions and 23 deletions

View file

@ -55,6 +55,33 @@ You can also provide metadata at the per-database or per-table level, like this:
Each of the top-level metadata fields can be used at the database and table level.
Setting which columns can be used for sorting
---------------------------------------------
Datasette allows any column to be used for sorting by default. If you need to
control which columns are available for sorting you can do so using the optional
``sortable_columns`` key::
{
"databases": {
"database1": {
"tables": {
"example_table": {
"sortable_columns": [
"height",
"weight"
]
}
}
}
}
}
This will restrict sorting of ``example_table`` to just the ``height`` and
``weight`` columns.
You can also disable sorting entirely by setting ``"sortable_columns": []``
Generating a metadata skeleton
------------------------------