# HG changeset patch # User Adrien Di Mascio # Date 1318575879 -7200 # Node ID 48330faf4cd721133b61ac7479317546edb3804a # Parent deb596dc343a4d8e9b5fa495cf2004a37df65072 [table] use explicit add_onload() to setup table sorting (closes #2013493) diff -r deb596dc343a -r 48330faf4cd7 web/data/cubicweb.ajax.js --- a/web/data/cubicweb.ajax.js Thu Oct 13 11:49:19 2011 +0200 +++ b/web/data/cubicweb.ajax.js Fri Oct 14 09:04:39 2011 +0200 @@ -257,10 +257,6 @@ } function _postAjaxLoad(node) { - // find sortable tables if there are some - if (typeof(Sortable) != 'undefined') { - Sortable.sortTables(node); - } // find textareas and wrap them if there are some if (typeof(FCKeditor) != 'undefined') { buildWysiwygEditors(); diff -r deb596dc343a -r 48330faf4cd7 web/data/jquery.tablesorter.js --- a/web/data/jquery.tablesorter.js Thu Oct 13 11:49:19 2011 +0200 +++ b/web/data/jquery.tablesorter.js Fri Oct 14 09:04:39 2011 +0200 @@ -874,5 +874,3 @@ Sortable.sortTables = function() { jQuery("table.listing").tablesorter({textExtraction: cubicwebSortValueExtraction}); }; - -jQuery(document).ready(Sortable.sortTables); diff -r deb596dc343a -r 48330faf4cd7 web/views/tableview.py --- a/web/views/tableview.py Thu Oct 13 11:49:19 2011 +0200 +++ b/web/views/tableview.py Fri Oct 14 09:04:39 2011 +0200 @@ -24,7 +24,7 @@ from cubicweb import NoSelectableObject, tags from cubicweb.selectors import nonempty_rset -from cubicweb.utils import make_uid, json_dumps +from cubicweb.utils import make_uid, js_dumps, JSString from cubicweb.view import EntityView, AnyRsetView from cubicweb.uilib import toggle_action, limitsize, htmlescape from cubicweb.web import jsonize, component, facet @@ -45,6 +45,10 @@ table_widget_class = TableWidget table_column_class = TableColumn + tablesorter_settings = { + 'textExtraction': JSString('cubicwebSortValueExtraction'), + } + def form_filter(self, divid, displaycols, displayactions, displayfilter, paginate, hidden=True): try: @@ -84,6 +88,15 @@ displaycols = range(len(self.cw_rset.syntax_tree().children[0].selection)) return displaycols + def _setup_tablesorter(self, divid): + req = self._cw + req.add_js('jquery.tablesorter.js') + req.add_onload('''$(document).ready(function() { + $("#%s table.listing").tablesorter(%s); +});''' % (divid, js_dumps(self.tablesorter_settings))) + req.add_css(('cubicweb.tablesorter.css', 'cubicweb.tableview.css')) + + def call(self, title=None, subvid=None, displayfilter=None, headers=None, displaycols=None, displayactions=None, actions=(), divid=None, cellvids=None, cellattrs=None, mainindex=None, @@ -98,8 +111,8 @@ :param displayactions: if True, display action menu """ req = self._cw - req.add_js('jquery.tablesorter.js') - req.add_css(('cubicweb.tablesorter.css', 'cubicweb.tableview.css')) + divid = divid or req.form.get('divid') or 'rs%s' % make_uid(id(self.cw_rset)) + self._setup_tablesorter(divid) # compute label first since the filter form may remove some necessary # information from the rql syntax tree if mainindex is None: @@ -108,7 +121,6 @@ hidden = True if not subvid and 'subvid' in req.form: subvid = req.form.pop('subvid') - divid = divid or req.form.get('divid') or 'rs%s' % make_uid(id(self.cw_rset)) actions = list(actions) if mainindex is None: displayfilter, displayactions = False, False