|
64 | 64 | }; |
65 | 65 | options = $.extend(defaults, options); |
66 | 66 |
|
| 67 | + // Variable array for holding <thead> and <tfoot> from each table |
| 68 | + // As we split a table we need to keep copies of the <thead> and <tfoot> to place on each column |
| 69 | + var tables = new Array(); |
| 70 | + |
| 71 | + // Find all the table elements in the page |
| 72 | + $('table').each(function () { |
| 73 | + // Check if we have not already saved the <thead> and <tfoot> |
| 74 | + if (!$(this).hasClass('tableSaved')) { |
| 75 | + // Mark the found table by adding the .tableSaved class |
| 76 | + $(this).addClass('tableSaved') |
| 77 | + // Give the table a unique ID so we can re-add its elements later |
| 78 | + $(this).addClass('tableID-' + tables.length) |
| 79 | + // Save the tables unique ID, <thead>, and <tfoot> as an object in our tables array |
| 80 | + tables.push({ |
| 81 | + tableID: 'tableID-' + tables.length, |
| 82 | + thead: $(this).find('thead:first').clone(), |
| 83 | + tfoot: $(this).find('tfoot:first').clone() |
| 84 | + }); |
| 85 | + } |
| 86 | + }); |
| 87 | + |
| 88 | + // Function to add <thead> and <tfoot> to all tables in $pullOutHere |
| 89 | + // This function should be called anywhere split() returns as |
| 90 | + // that is the point where a column is complete and the remaining content |
| 91 | + // is not going to change until the next columnize() is called |
| 92 | + function fixTables($pullOutHere) { |
| 93 | + // Iterate through all of our saved tables |
| 94 | + for (i = 0; i < tables.length; i++) { |
| 95 | + // Check if the root element is a table |
| 96 | + if ($pullOutHere.is("table")) { |
| 97 | + // Check if the root element has any <tfoot> elements and |
| 98 | + // is the current table id for this loop |
| 99 | + if ($pullOutHere.children('tfoot').length == 0 && |
| 100 | + $pullOutHere.hasClass(tables[i].tableID)) { |
| 101 | + // Add the <tfoot> to the table |
| 102 | + $(tables[i].tfoot).clone().prependTo($pullOutHere); |
| 103 | + } |
| 104 | + // Check if the root element has any <tfoot> elements and |
| 105 | + // is the current table id for this loop |
| 106 | + if ($pullOutHere.children('thead').length == 0 && |
| 107 | + $pullOutHere.hasClass(tables[i].tableID)) { |
| 108 | + // Add the <tfoot> to the table |
| 109 | + $(tables[i].thead).clone().prependTo($pullOutHere); |
| 110 | + } |
| 111 | + } |
| 112 | + // Check if there are any child tables to the root element with the current table ID |
| 113 | + $pullOutHere.find('table .' + tables[i].tableID).each(function () { |
| 114 | + // Check if the child table has no <tfoot> |
| 115 | + if ($(this).children('tfoot').length == 0) { |
| 116 | + // Add the <tfoot> to the table |
| 117 | + $(tables[i].tfoot).clone().prependTo(this); |
| 118 | + } |
| 119 | + // Check if the child table has no <thead> |
| 120 | + if ($(this).children('thead').length == 0) { |
| 121 | + // Add the <thead> to the table |
| 122 | + $(tables[i].thead).clone().prependTo(this); |
| 123 | + } |
| 124 | + }); |
| 125 | + } |
| 126 | + } |
| 127 | + |
67 | 128 | if(typeof(options.width) == "string"){ |
68 | 129 | options.width = parseInt(options.width,10); |
69 | 130 | if(isNaN(options.width)){ |
|
187 | 248 | */ |
188 | 249 | function columnize($putInHere, $pullOutHere, $parentColumn, targetHeight){ |
189 | 250 |
|
190 | | - // Variables for dealing with <thead> and <tfoot> when splitting tables |
191 | | - // As we split a table we need to keep copies of the <thead> and <tfoot> to place on each column |
192 | | - var $thead; |
193 | | - var $tfoot; |
194 | | - |
195 | 251 | // |
196 | 252 | // add as many nodes to the column as we can, |
197 | 253 | // but stop once our height is too tall |
|
300 | 356 | */ |
301 | 357 | function split($putInHere, $pullOutHere, $parentColumn, targetHeight){ |
302 | 358 | if($putInHere.contents(":last").find(prefixTheClassName("columnbreak", true)).length){ |
| 359 | + // Fix any tables that have had their <thead> and <tfoot> moved |
| 360 | + fixTables($pullOutHere); |
303 | 361 | // |
304 | 362 | // our column is on a column break, so just end here |
305 | 363 | return; |
306 | 364 | } |
307 | 365 | if($putInHere.contents(":last").hasClass(prefixTheClassName("columnbreak"))){ |
| 366 | + // Fix any tables that have had their <thead> and <tfoot> moved |
| 367 | + fixTables($pullOutHere); |
308 | 368 | // |
309 | 369 | // our column is on a column break, so just end here |
310 | 370 | return; |
|
395 | 455 | } |
396 | 456 | } |
397 | 457 | } |
398 | | - // If we are in the process of splitting a table, add the <thead> and <tfoot> |
399 | | - // clones back to $pullOutHere so they are available to move into the next column |
400 | | - if($pullOutHere.prop('tagName') == 'TABLE'){ |
401 | | - if (this.$thead){ |
402 | | - $pullOutHere.prepend(this.$tfoot); |
403 | | - } |
404 | | - if (this.$thead) { |
405 | | - $pullOutHere.prepend(this.$thead); |
406 | | - } |
407 | | - } |
408 | | - |
| 458 | + // Fix any tables that have had their <thead> and <tfoot> moved |
| 459 | + fixTables($pullOutHere); |
409 | 460 | } |
410 | 461 |
|
411 | 462 |
|
|
0 commit comments