Skip to content

Commit

Permalink
Added sortBy parameter to Table panel (#612)
Browse files Browse the repository at this point in the history
  • Loading branch information
Git-Lior authored Sep 7, 2023
1 parent 1e8452e commit 019b34b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
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

0 comments on commit 019b34b

Please sign in to comment.