Skip to content

Commit

Permalink
🏓 Datatables options (#308)
Browse files Browse the repository at this point in the history
* Adds datatables_options for BaseModelView

* Fixes lint error
  • Loading branch information
mrharpo authored Sep 26, 2023
1 parent fb62f16 commit e351ddc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions starlette_admin/statics/js/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ $(function () {
.container()
.appendTo("#pageLength_container");
},
...model.datatablesOptions,
});

$("#searchInput").on("keyup", function () {
Expand Down
5 changes: 5 additions & 0 deletions starlette_admin/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Any,
Awaitable,
Callable,
ClassVar,
Dict,
List,
Optional,
Expand Down Expand Up @@ -205,6 +206,8 @@ class BaseModelView(BaseView):
responsive_table: Enable/Disable [responsive](https://datatables.net/extensions/responsive/)
extension
save_state: Enable/Disable [state saving](https://datatables.net/examples/basic_init/state_save.html)
datatables_options: Dict of [Datatables options](https://datatables.net/reference/option/).
These will overwrite any default options set for the datatable.
list_template: List view template. Default is `list.html`.
detail_template: Details view template. Default is `details.html`.
create_template: Edit view template. Default is `edit.html`.
Expand Down Expand Up @@ -240,6 +243,7 @@ class BaseModelView(BaseView):
page_size_options: Sequence[int] = [10, 25, 50, 100]
responsive_table: bool = False
save_state: bool = True
datatables_options: ClassVar[Dict[str, Any]] = {}
list_template: str = "list.html"
detail_template: str = "detail.html"
create_template: str = "create.html"
Expand Down Expand Up @@ -758,4 +762,5 @@ async def _configs(self, request: Request) -> Dict[str, Any]:
"dt_i18n_url": request.url_for(
f"{request.app.state.ROUTE_NAME}:statics", path=f"i18n/dt/{locale}.json"
),
"datatablesOptions": self.datatables_options,
}

0 comments on commit e351ddc

Please sign in to comment.