Added sortable attribute to columns
authorThierry Florac <thierry.florac@onf.fr>
Mon, 12 Mar 2018 16:44:36 +0100
changeset 284 a92b2319a8c5
parent 283 c69daf695ed9
child 285 24f16ae945c8
Added sortable attribute to columns
src/pyams_skin/table.py
--- a/src/pyams_skin/table.py	Sun Mar 11 11:23:42 2018 +0100
+++ b/src/pyams_skin/table.py	Mon Mar 12 16:44:36 2018 +0100
@@ -78,6 +78,7 @@
             },
             'th': {
                 'data-ams-column-name': lambda x, col: x.__name__,
+                'data-ams-datatable-sortable': self.get_sortable_column,
                 'data-ams-datatable-stype': self.get_column_type
             }
         }
@@ -98,6 +99,10 @@
         return self.request.params.get(self.prefix + '-sortOrder', self.sortOrder)
 
     @staticmethod
+    def get_sortable_column(column, _=None):
+        return getattr(column, 'dt_sortable', None)
+
+    @staticmethod
     def get_column_type(column, _=None):
         return getattr(column, 'dt_sort_type', None)
 
@@ -215,6 +220,8 @@
     checker = None
     permission = None
 
+    dt_sortable = 'false'
+
     def renderCell(self, item):
         if not self.has_permission(item):
             return ''