From a3dc8ab3d766284af97641c7f93a5c43cc13781a Mon Sep 17 00:00:00 2001 From: Denis Flaven Date: Fri, 26 Aug 2011 10:33:37 +0000 Subject: [PATCH] Added the ability to reload a selection fro a paginated list. SVN:trunk[1524] --- js/jquery.tablesorter.pager.js | 114 +++++++++++++++++++-------------- 1 file changed, 65 insertions(+), 49 deletions(-) diff --git a/js/jquery.tablesorter.pager.js b/js/jquery.tablesorter.pager.js index 3736b698bb..1813a44a1a 100644 --- a/js/jquery.tablesorter.pager.js +++ b/js/jquery.tablesorter.pager.js @@ -105,7 +105,7 @@ function sprintf(format, etc) { $(':input[name^=storedSelection]', pager).remove(); } - function updateSelection(table, pager, id, value) + function storeSelection(table, pager, id, value) { var valueToStore = value; if (table.config.selectionMode == 'negative') @@ -133,6 +133,12 @@ function sprintf(format, etc) { updateCounter(table, pager); } + function loadSelection(table, pager) + { + table.config.selectionMode = $(pager).find(':input[name=selectionMode]').val(); + updateCounter(table, pager); + } + function updateCounter(table, pager) { var ex = $(':input[name^=storedSelection]', pager).length; @@ -205,53 +211,7 @@ function sprintf(format, etc) { } fixPosition(table,tableBody); - if (c.selectionMode == 'negative') - { - $(table).find(':checkbox[name^=selectObj]').attr('checked', true); - } - - if (table.config.select_mode == 'multiple') - { - $(table).find(':checkbox[name^=selectObj]').each(function() { - var id = parseInt(this.value, 10); - if ($('#'+id, table.config.container).length > 0) - { - if (c.selectionMode == 'positive') - { - $(this).attr('checked', true); - } - else - { - $(this).attr('checked', false); - } - } - }); - - $(table).find(':checkbox[name^=selectObj]').change(function() { - updateSelection(table, table.config.container, this.value, this.checked); - }); - } - else if (table.config.select_mode == 'single') - { - $(table).find('input[name^=selectObject]:radio').each(function() { - var id = parseInt(this.value, 10); - if ($('#'+id, table.config.container).length > 0) - { - if (c.selectionMode == 'positive') - { - $(this).attr('checked', true); - } - else - { - $(this).attr('checked', false); - } - } - }); - - $(table).find('input[name^=selectObject]:radio').change(function() { - updateSelection(table, table.config.container, this.value, this.checked); - }); - } + applySelection(table); $(table).trigger("applyWidgets"); @@ -267,6 +227,58 @@ function sprintf(format, etc) { }); } + function applySelection(table) + { + var c = table.config; + if (c.selectionMode == 'negative') + { + $(table).find(':checkbox[name^=selectObj]').attr('checked', true); + } + + if (table.config.select_mode == 'multiple') + { + $(table).find(':checkbox[name^=selectObj]').each(function() { + var id = parseInt(this.value, 10); + if ($('#'+id, table.config.container).length > 0) + { + if (c.selectionMode == 'positive') + { + $(this).attr('checked', true); + } + else + { + $(this).attr('checked', false); + } + } + }); + + $(table).find(':checkbox[name^=selectObj]').change(function() { + storeSelection(table, table.config.container, this.value, this.checked); + }); + } + else if (table.config.select_mode == 'single') + { + $(table).find('input[name^=selectObject]:radio').each(function() { + var id = parseInt(this.value, 10); + if ($('#'+id, table.config.container).length > 0) + { + if (c.selectionMode == 'positive') + { + $(this).attr('checked', true); + } + else + { + $(this).attr('checked', false); + } + } + }); + + $(table).find('input[name^=selectObject]:radio').change(function() { + storeSelection(table, table.config.container, this.value, this.checked); + }); + } + } + function renderPager(table, pager) { var c = table.config; @@ -400,9 +412,13 @@ function sprintf(format, etc) { $(table).find(':checkbox.checkAll').removeAttr('onclick').click(function() { return checkAll(table, pager, this.checked); }); + + $(table).bind('load_selection', function() { + loadSelection(table, pager); + applySelection(table); + }); }); }; - } }); // extend plugin scope