From ee566723d70b05fa6cc583bf66ba6acd7c46b8e2 Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Wed, 9 Feb 2022 14:31:40 -0500 Subject: [PATCH] Document supported table columns --- docs/plugins/development/tables.md | 52 ++++++++++++++++++++++++++++++ netbox/netbox/tables/columns.py | 12 ++++--- 2 files changed, 59 insertions(+), 5 deletions(-) diff --git a/docs/plugins/development/tables.md b/docs/plugins/development/tables.md index 009d5671a..393df48a9 100644 --- a/docs/plugins/development/tables.md +++ b/docs/plugins/development/tables.md @@ -46,3 +46,55 @@ table.configure(request) ``` If using a generic view provided by NetBox, table configuration is handled automatically. + +## Columns + +The table column classes listed below are supported for use in plugins. These classes can be imported from `netbox.tables.columns`. + +::: netbox.tables.BooleanColumn + rendering: + show_source: false + selection: + members: false + +::: netbox.tables.ColorColumn + rendering: + show_source: false + selection: + members: false + +::: netbox.tables.ColoredLabelColumn + rendering: + show_source: false + selection: + members: false + +::: netbox.tables.ContentTypeColumn + rendering: + show_source: false + selection: + members: false + +::: netbox.tables.ContentTypesColumn + rendering: + show_source: false + selection: + members: false + +::: netbox.tables.MarkdownColumn + rendering: + show_source: false + selection: + members: false + +::: netbox.tables.TagColumn + rendering: + show_source: false + selection: + members: false + +::: netbox.tables.TemplateColumn + rendering: + show_source: false + selection: + members: false diff --git a/netbox/netbox/tables/columns.py b/netbox/netbox/tables/columns.py index 284691469..cfc220536 100644 --- a/netbox/netbox/tables/columns.py +++ b/netbox/netbox/tables/columns.py @@ -75,7 +75,8 @@ class BooleanColumn(tables.Column): class TemplateColumn(tables.TemplateColumn): """ - Overrides the stock TemplateColumn to render a placeholder if the returned value is an empty string. + Overrides django-tables2's stock TemplateColumn class to render a placeholder symbol if the returned value + is an empty string. """ PLACEHOLDER = mark_safe('—') @@ -219,7 +220,7 @@ class ContentTypesColumn(tables.ManyToManyColumn): class ColorColumn(tables.Column): """ - Display a color (#RRGGBB). + Display an arbitrary color value, specified in RRGGBB format. """ def render(self, value): return mark_safe( @@ -232,7 +233,8 @@ class ColorColumn(tables.Column): class ColoredLabelColumn(tables.TemplateColumn): """ - Render a colored label (e.g. for DeviceRoles). + Render a related object as a colored label. The related object must have a `color` attribute (specifying + an RRGGBB value) and a `get_absolute_url()` method. """ template_code = """ {% load helpers %} @@ -283,7 +285,7 @@ class LinkedCountColumn(tables.Column): class TagColumn(tables.TemplateColumn): """ - Display a list of tags assigned to the object. + Display a list of Tags assigned to the object. """ template_code = """ {% load helpers %} @@ -342,7 +344,7 @@ class CustomFieldColumn(tables.Column): class CustomLinkColumn(tables.Column): """ - Render a custom links as a table column. + Render a custom link as a table column. """ def __init__(self, customlink, *args, **kwargs): self.customlink = customlink