Choosing and moving table columns
- Tables now get a column for each table with an indexed foreign key that points at them, after the many-to-many columns, headed for example "reviews where movie_id = this". Each cell has pills for the 5 most recent rows that point at that row and an "N total" link, like the row page's "Related rows" section added in 1.0a46. (#3138, #3164)
- Many-to-many columns and these new columns can be mixed in with the table's own columns and moved among them.
?_col=takesm2m:and the name of a relationship, such asm2m:movie_actors, orref:and a table and column that point at this table, such asref:reviews.movie_id, alongside column names, in the order to show them.?_nocol=can hide them in the same way. See Special table arguments. - Column headings can be dragged to move their column, on desktop. Dropping a column on the red "Hide column" area at the left of the screen, or pressing
Delete,BackspaceorDwhile dragging it, hides it. The table changes in place without reloading the page, and the address bar and the page's links and forms are updated to match. - A new Columns button above the table opens the dialog for choosing columns, which can now choose and order relationship columns too. When the columns shown are not the default it says how many are shown, such as "Columns · 5 of 14", and whether they are personalized or came from the link. It replaces "Choose columns" in each column's menu.
- The table page remembers the columns chosen for each table in the browser's local storage. A link to the table without
?_col=or?_nocol=, such as a row page's breadcrumbs, then shows those columns. A link with either is always shown as it is and never remembered, so a shared link shows everyone the same columns. "Reset to default" in the dialog forgets them. - New relationship_time_limit_ms setting, 500ms by default, for the queries that fetch the related rows shown on table and row pages. It is one budget for each page, shared by all of its relationships, so relationship columns add at most that much time to a page however many there are. These queries previously used facet_time_limit_ms (200ms) each.
- Relationship headings and cells on the table page now have a
relationship-colCSS class.
Label templates and setting a table's label column
- A table's label_column can now be a label template that combines several columns, such as
"{first_name} {last_name}", as well as the name of a single column. Templates are compiled into a SQL expression, so they work everywhere labels are used: foreign key links,?_labels=on, facets, autocomplete and the pills for related rows and many-to-many relationships. (#3165) - New set-label-column permission. Actors who have it get a "Set label column" item in the table actions menu, with a dialog for choosing the default label, a column or a template, and a preview of the first five rows' labels. The label is saved in the internal database and takes priority over the
label_columnconfiguration. (#3165) - New
POST /<database>/<table>/-/set-label-columnAPI for saving or removing a table's label column or template. See Setting the label column. (#3165) - New internals for plugins: db.table_label(),
db.label_sql_for_table()anddb.detected_label_column(), and datasette.get_label_column() and datasette.set_label_column().db.label_column_for_table()returnsNonefor a table whose label is a template, since callers use its result as a column name. (#3165) - Label column detection has changed. A
nameortitlecolumn now wins over a unique text column, so auserstable with a uniqueemailcolumn is labelled by its name. A text primary key is only used as the label when nothing else applies, and the rule for tables with two columns now uses the primary key whatever it is called. See label_column for the rules. (#3163) - A configured
label_columnthat is not a column of the table is now ignored, with a warning in the log, and the label column is detected instead. Previously it made the pages of that table, and of every table linked to it, fail with "no such column". The configured name is now matched case-insensitively. (#3163)
Create table from data
- "Create table from data" can now import a CSV or TSV file with blank or repeated column headers, such as one with a trailing comma on every line. A blank header is named
untitled_and its position, and a repeated one gets_2,_3and so on, with a note under the preview saying which columns were renamed. (#3168) - Column names can be edited in the preview. Blank and duplicate names are marked as you type, and stop the table being created. (#3168)
- A column can be skipped, using its type menu. It stays in the preview, greyed out, and is left out of the table. (#3168)
Breaking changes
- Backwards incompatible, since 1.0a45:
?_col=is now the complete list of the table page's columns, relationship columns included. With?_col=, many-to-many columns it does not list are not shown, and the m2m extra only returns the relationships it lists, so?_col=title&_extra=m2mreturns none. Previously?_col=did not affect relationships. This only changes the many-to-many columns added in 1.0a45. - Backwards incompatible, since 1.0a45: the
?_nom2m=1argument added in 1.0a45 has been removed. Use?_nocol=m2m:NAMEor a?_col=list to hide relationship columns, or"m2m": falsein the table configuration to turn them off. - Backwards incompatible, since 1.0a45: tables with more than 10 detected many-to-many relationships and no
m2mconfiguration list still show only the first 10, but the table and row pages no longer say so, and them2mextra no longer adds a top-levelm2m_cappedkey.?_col=m2m:NAMEshows one beyond the first 10. See at most 10 relationships for each table. - Backwards incompatible, since 1.0a45 and 1.0a46: template variables for relationships have changed, for custom templates. Table templates get
table_columns, every column in the order shown with itskind(col,m2morref), and each row hasrow.table_cellsin the same order, replacingm2m_columnsandrow.m2m_cellsfrom 1.0a45. Row templates getrelated_rows, one list of sections for the "Related rows" section, replacingm2m_sectionsfrom 1.0a45 andreferenced_byfrom 1.0a46.m2m_cappedhas been removed from both.
Other changes
- The column actions menu now shows the column's type beside its name, such as "TEXT" or "VARCHAR(255) NOT NULL", instead of in a footer below the actions. This applies to table pages and to the column menus on SQL query results.
Security fix
- Fixed a security issue where the labels of rows in a table an actor could not view were shown to them on other pages. In the "Related rows" section of the row page, added in 1.0a46, a table with no label column of its own has its rows labelled by the row that its other foreign key points to, and that label was used without checking that the actor could view the table it came from. For example, with a private
userstable, a visitor who could viewmoviesandreviewssaw the names of the users who wrote each review. Those rows are now labelled by their own primary key unless the actor can view the other table.