Added "getSelectedRowClass" to get CSS class dynamically for a given row
authorThierry Florac <thierry.florac@onf.fr>
Wed, 27 Jun 2018 15:00:54 +0200
changeset 357 f3b8efc86004
parent 356 95f6d62d425b
child 358 39ee3f076d70
Added "getSelectedRowClass" to get CSS class dynamically for a given row
src/pyams_skin/table.py
--- a/src/pyams_skin/table.py	Wed Jun 27 14:59:27 2018 +0200
+++ b/src/pyams_skin/table.py	Wed Jun 27 15:00:54 2018 +0200
@@ -162,6 +162,16 @@
 
     render = get_view_template()
 
+    def getSelectedRowClass(self, row, cssClass=None):
+        klass = self.cssClasses.get('tr.selected')
+        if callable(klass):
+            klass = klass(*row)
+        if klass and cssClass:
+            klass = '{0} {1}'.format(klass, cssClass)
+        elif cssClass:
+            klass = cssClass
+        return klass or ''
+
     def renderTable(self):
         return super(BaseTable, self).renderTable() \
             .replace('<table', '<table %s' % self.get_data_attributes('table', self))
@@ -174,6 +184,7 @@
                       request=self.request)
 
     def renderRow(self, row, cssClass=None):
+        cssClass = self.getSelectedRowClass(row[0], cssClass)
         return super(BaseTable, self).renderRow(row, cssClass) \
             .replace('<tr', '<tr %s' % self.get_data_attributes('tr', row[0][0]))