Skip to content

Commit

Permalink
Added sortBy parameter to Table panel
Browse files Browse the repository at this point in the history
  • Loading branch information
Git-Lior committed Jul 31, 2023
1 parent 0dce0f6 commit 287e4c5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Changelog
* Extended SqlTarget to support parsing queries from files
* Fix AlertCondition backwards compatibility (``useNewAlerts`` default to ``False``)
* Added RateMetricAgg_ for ElasticSearch
* 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
17 changes: 16 additions & 1 deletion grafanalib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3179,6 +3179,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 @@ -3197,6 +3209,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 @@ -3210,6 +3223,7 @@ 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))

@classmethod
def with_styled_columns(cls, columns, styles=None, **kwargs):
Expand Down Expand Up @@ -3241,7 +3255,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 287e4c5

Please sign in to comment.