Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added sortBy parameter to Table panel #612

Merged
merged 1 commit into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Changelog
* Added RateMetricAgg_ for ElasticSearch
* added axisSoftMin and axisSoftMax options for TimeSeries
* Added support for Azure Data Explorer datasource plugin (https://github.com/grafana/azure-data-explorer-datasource)
* Added ``sortBy`` parameter to Table panel

.. _`Bar_Chart`: https://grafana.com/docs/grafana/latest/panels-visualizations/visualizations/bar-chart/
.. _`RateMetricAgg`: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-rate-aggregation.html
Expand Down
20 changes: 19 additions & 1 deletion grafanalib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3185,6 +3185,18 @@ def to_json_data(self):
}


@attr.s
class TableSortByField(object):
displayName = attr.ib(default="")
desc = attr.ib(default=False)

def to_json_data(self):
return {
'displayName': self.displayName,
'desc': self.desc,
}


@attr.s
class Table(Panel):
"""Generates Table panel json structure
Expand All @@ -3203,6 +3215,7 @@ class Table(Panel):
:param overrides: To override the base characteristics of certain data
:param showHeader: Show the table header
:param unit: units
:param sortBy: Sort rows by table fields
"""

align = attr.ib(default='auto', validator=instance_of(str))
Expand All @@ -3216,6 +3229,10 @@ class Table(Panel):
showHeader = attr.ib(default=True, validator=instance_of(bool))
span = attr.ib(default=6),
unit = attr.ib(default='', validator=instance_of(str))
sortBy = attr.ib(default=attr.Factory(list), validator=attr.validators.deep_iterable(
member_validator=instance_of(TableSortByField),
iterable_validator=instance_of(list)
))

@classmethod
def with_styled_columns(cls, columns, styles=None, **kwargs):
Expand Down Expand Up @@ -3247,7 +3264,8 @@ def to_json_data(self):
'mappings': self.mappings,
'minSpan': self.minSpan,
'options': {
'showHeader': self.showHeader
'showHeader': self.showHeader,
'sortBy': self.sortBy
},
'type': TABLE_TYPE,
}
Expand Down
Loading