ID | headline | pub date |
---|
When a user searches a datatable, the server will query all of the concrete fields in the displayed columns. You can enable extra search fields that are not shown on the table, but are consulted during a search query, by adding datatable_options["search_fields"]
.
search_fields
is a simple list of fields using the normal query language. In this case, "blog__name"
has been added to the list of fields, and so you can search the above table for the term First
or Second
and see the table filter the results, even though that field is not included as a real column.
class SearchFieldsDatatableView(DatatableView): model = Entry datatable_options = { 'columns': [ 'id', 'headline', 'pub_date', ], 'search_fields': ['blog__name'], }