From 3c1ea5d0fb2fabeda539e1cdc23e62bcd15b7b8d Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Thu, 27 Jan 2022 16:14:02 -0500 Subject: [PATCH] Closes #8470: Expose NetBoxTable in the plugins framework --- docs/plugins/development/tables.md | 37 ++++++++++++++++++++++++++++++ mkdocs.yml | 5 ++-- 2 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 docs/plugins/development/tables.md diff --git a/docs/plugins/development/tables.md b/docs/plugins/development/tables.md new file mode 100644 index 000000000..16f9f6c17 --- /dev/null +++ b/docs/plugins/development/tables.md @@ -0,0 +1,37 @@ +# Tables + +NetBox employs the [`django-tables2`](https://django-tables2.readthedocs.io/) library for rendering dynamic object tables. These tables display lists of objects, and can be sorted and filtered by various parameters. + +## NetBoxTable + +To provide additional functionality beyond what is supported by the stock `Table` class in `django-tables2`, NetBox provides the `NetBoxTable` class. This custom table class includes support for: + +* User-configurable column display and ordering +* Custom field & custom link columns +* Automatic prefetching of related objects + +It also includes several default columns: + +* `pk` - A checkbox for selecting the object associated with each table row +* `id` - The object's numeric database ID, as a hyperlink to the object's view +* `actions` - A dropdown menu presenting object-specific actions available to the user. + +### Example + +```python +# tables.py +import django_tables2 as tables +from netbox.tables import NetBoxTable +from .models import MyModel + +class MyModelTable(NetBoxTable): + name = tables.Column( + linkify=True + ) + ... + + class Meta(NetBoxTable.Meta): + model = MyModel + fields = ('pk', 'id', 'name', ...) + default_columns = ('pk', 'name', ...) +``` diff --git a/mkdocs.yml b/mkdocs.yml index 1a77cb195..3b1e52f50 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -102,9 +102,10 @@ nav: - Using Plugins: 'plugins/index.md' - Developing Plugins: - Getting Started: 'plugins/development/index.md' - - Database Models: 'plugins/development/models.md' + - Models: 'plugins/development/models.md' - Views: 'plugins/development/views.md' - - Filtersets: 'plugins/development/filtersets.md' + - Tables: 'plugins/development/tables.md' + - Filter Sets: 'plugins/development/filtersets.md' - REST API: 'plugins/development/rest-api.md' - Background Tasks: 'plugins/development/background-tasks.md' - Administration: