From d4b8f8b34d8d92a31b1b58194f39b31a13007109 Mon Sep 17 00:00:00 2001 From: Jordan Bradford Date: Tue, 31 Jan 2017 15:25:07 -0600 Subject: [PATCH] added multiTable option to stackcolumns() to split the final output into multiple tables --- README.md | 1 + stacktable.js | 34 ++++++++++++++++++++++++++++++---- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1e99b53..9192727 100755 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ The Responsive Tables jQuery plugin for stacking tables on small screens. The pu **headIndex:** Use this to specify the row index of the header, in case it isn’t the first. +**multiTable:** [For `.stackcolumns()` only] - Boolean that defaults to false. Use this to split the final output into multiple tables. # Legal diff --git a/stacktable.js b/stacktable.js index 23fb274..58a152c 100755 --- a/stacktable.js +++ b/stacktable.js @@ -148,8 +148,17 @@ $.fn.stackcolumns = function(options) { var $tables = this, - defaults = {}, - settings = $.extend({}, defaults, options); + defaults = {multiTable:false}, + settings = $.extend({}, defaults, options), + multiTable; + + // checking the "multiTable" option presence... or defaults it to false + if(typeof options.multiTable !== 'undefined') { + multiTable = options.multiTable; + } + else { + multiTable = false; + } return $tables.each(function() { var $table = $(this); @@ -195,8 +204,25 @@ ++col_i; } - $stackcolumns.append($(tb)); - $table.before($stackcolumns); + if (multiTable) { + var tempTable, + tempRows, + numTables = tb.find('.st-head-row-main').length; + for(var i = 0; i < numTables; i++) { + tempTable = $stackcolumns.clone(); + if(i < numTables - 1) { + tempRows = tb.find('.st-head-row-main').eq(i).nextUntil('.st-head-row-main').addBack(); + } else { + tempRows = tb.find('.st-head-row-main').eq(i).nextAll().addBack(); + } + tempTable.append(tempRows.clone()); + tempTable.addClass('stacktable-' + i).children().wrapAll(''); + $table.before(tempTable); + } + } else { + $stackcolumns.append($(tb)); + $table.before($stackcolumns); + } }); };