mirror of
https://github.com/Mottie/tablesorter.git
synced 2024-11-15 23:54:22 +00:00
Merge pull request #822 from prijutme4ty/fix_multiple_tbodies_cache
Fix multiple tbodies cache
This commit is contained in:
commit
62cda37d60
@ -135,18 +135,15 @@
|
||||
},
|
||||
|
||||
calcFilters = function(table, p) {
|
||||
var tbodyIndex,
|
||||
c = table.config,
|
||||
var c = table.config,
|
||||
hasFilters = c.$table.hasClass('hasFilters');
|
||||
if (hasFilters && !p.ajaxUrl) {
|
||||
if ($.isEmptyObject(c.cache)) {
|
||||
// delayInit: true so nothing is in the cache
|
||||
p.filteredRows = p.totalRows = c.$tbodies.eq(0).children('tr').not( p.countChildRows ? '' : '.' + c.cssChildRow ).length;
|
||||
} else {
|
||||
// just in case the pager tbody isn't the first tbody
|
||||
tbodyIndex = c.$table.children('tbody').index( c.$tbodies.eq(0) );
|
||||
p.filteredRows = 0;
|
||||
$.each(c.cache[tbodyIndex].normalized, function(i, el) {
|
||||
$.each(c.cache[0].normalized, function(i, el) {
|
||||
p.filteredRows += p.regexRows.test(el[c.columns].$row[0].className) ? 0 : 1;
|
||||
});
|
||||
}
|
||||
@ -659,8 +656,7 @@
|
||||
c.$table.trigger('updateCache', [ function(){
|
||||
var i,
|
||||
rows = [],
|
||||
tbodyIndex = c.$table.children('tbody').index( c.$tbodies.eq(0) ),
|
||||
n = table.config.cache[tbodyIndex].normalized;
|
||||
n = table.config.cache[0].normalized;
|
||||
p.totalRows = n.length;
|
||||
for (i = 0; i < p.totalRows; i++) {
|
||||
rows.push(n[i][c.columns].$row);
|
||||
|
@ -5325,12 +5325,12 @@ var config = $('#mytable').data('tablesorter');
|
||||
<tr id="variable-cache">
|
||||
<td><a href="#" class="permalink">config.cache</a></td>
|
||||
<td>Object</td>
|
||||
<td>Internal list of table contents (<span class="version">v2.0.18</span>; <span class="version updated">v2.19.1</span> )
|
||||
<td>Internal list of table contents (<span class="version">v2.0.18</span>; <span class="version updated">v2.19.2</span> )
|
||||
<div class="collapsible">
|
||||
<br>
|
||||
This object contains the following:<br>
|
||||
<ul>
|
||||
<li>tbody index
|
||||
<li>tbody index (non-info block only, numeration is the same as for <a href="#variable-tbodies"><code>config.$tbodies</code></a> <span class="version updated">v2.19.2</span>)
|
||||
<ul>
|
||||
<li><code>colMax</code>
|
||||
<ul>
|
||||
@ -5796,7 +5796,6 @@ var p = $('#mytable').data('tablesorter').pager;
|
||||
For example, if you want to get the parsed values for the rows currently displayed within the pager, use the <code>table.config.pager.cacheIndex</code> variable as follows:
|
||||
<pre class="prettyprint lang-js">var c = $('table')[0].config,
|
||||
p = c.pager,
|
||||
// the cache may not have a zero index if there are any "info-only" tbodies above the main tbody
|
||||
cache = c.cache[0].normalized,
|
||||
cachedValues = [];
|
||||
$.each( p.cacheIndex, function(i, v) {
|
||||
|
@ -136,7 +136,6 @@
|
||||
headerRow : 'tablesorter-headerRow',
|
||||
headerIn : 'tablesorter-header-inner',
|
||||
icon : 'tablesorter-icon',
|
||||
info : 'tablesorter-infoOnly',
|
||||
processing : 'tablesorter-processing',
|
||||
sortAsc : 'tablesorter-headerAsc',
|
||||
sortDesc : 'tablesorter-headerDesc',
|
||||
@ -295,10 +294,10 @@
|
||||
|
||||
/* utils */
|
||||
function buildCache(table) {
|
||||
var cc, t, tx, v, i, j, k, $row, rows, cols, cacheTime,
|
||||
var cc, t, tx, v, i, j, k, $row, cols, cacheTime,
|
||||
totalRows, rowData, colMax,
|
||||
c = table.config,
|
||||
$tb = c.$table.children('tbody'),
|
||||
$tb = c.$tbodies,
|
||||
extractors = c.extractors,
|
||||
parsers = c.parsers;
|
||||
c.cache = {};
|
||||
@ -321,68 +320,65 @@
|
||||
// colMax: # // added at the end
|
||||
};
|
||||
|
||||
// ignore tbodies with class name from c.cssInfoBlock
|
||||
if (!$tb.eq(k).hasClass(c.cssInfoBlock)) {
|
||||
totalRows = ($tb[k] && $tb[k].rows.length) || 0;
|
||||
for (i = 0; i < totalRows; ++i) {
|
||||
rowData = {
|
||||
// order: original row order #
|
||||
// $row : jQuery Object[]
|
||||
child: [], // child row text (filter widget)
|
||||
raw: [] // original row text
|
||||
};
|
||||
/** Add the table data to main data array */
|
||||
$row = $($tb[k].rows[i]);
|
||||
rows = [ new Array(c.columns) ];
|
||||
cols = [];
|
||||
// if this is a child row, add it to the last row's children and continue to the next row
|
||||
// ignore child row class, if it is the first row
|
||||
if ($row.hasClass(c.cssChildRow) && i !== 0) {
|
||||
t = cc.normalized.length - 1;
|
||||
cc.normalized[t][c.columns].$row = cc.normalized[t][c.columns].$row.add($row);
|
||||
// add 'hasChild' class name to parent row
|
||||
if (!$row.prev().hasClass(c.cssChildRow)) {
|
||||
$row.prev().addClass(ts.css.cssHasChild);
|
||||
totalRows = ($tb[k] && $tb[k].rows.length) || 0;
|
||||
for (i = 0; i < totalRows; ++i) {
|
||||
rowData = {
|
||||
// order: original row order #
|
||||
// $row : jQuery Object[]
|
||||
child: [], // child row text (filter widget)
|
||||
raw: [] // original row text
|
||||
};
|
||||
/** Add the table data to main data array */
|
||||
$row = $($tb[k].rows[i]);
|
||||
cols = [];
|
||||
// if this is a child row, add it to the last row's children and continue to the next row
|
||||
// ignore child row class, if it is the first row
|
||||
if ($row.hasClass(c.cssChildRow) && i !== 0) {
|
||||
t = cc.normalized.length - 1;
|
||||
cc.normalized[t][c.columns].$row = cc.normalized[t][c.columns].$row.add($row);
|
||||
// add 'hasChild' class name to parent row
|
||||
if (!$row.prev().hasClass(c.cssChildRow)) {
|
||||
$row.prev().addClass(ts.css.cssHasChild);
|
||||
}
|
||||
// save child row content (un-parsed!)
|
||||
rowData.child[t] = $.trim( $row[0].textContent || $row.text() || '' );
|
||||
// go to the next for loop
|
||||
continue;
|
||||
}
|
||||
rowData.$row = $row;
|
||||
rowData.order = i; // add original row position to rowCache
|
||||
for (j = 0; j < c.columns; ++j) {
|
||||
if (typeof parsers[j] === 'undefined') {
|
||||
if (c.debug) {
|
||||
log('No parser found for cell:', $row[0].cells[j], 'does it have a header?');
|
||||
}
|
||||
// save child row content (un-parsed!)
|
||||
rowData.child[t] = $.trim( $row[0].textContent || $row.text() || '' );
|
||||
// go to the next for loop
|
||||
continue;
|
||||
}
|
||||
rowData.$row = $row;
|
||||
rowData.order = i; // add original row position to rowCache
|
||||
for (j = 0; j < c.columns; ++j) {
|
||||
if (typeof parsers[j] === 'undefined') {
|
||||
if (c.debug) {
|
||||
log('No parser found for cell:', $row[0].cells[j], 'does it have a header?');
|
||||
}
|
||||
continue;
|
||||
}
|
||||
t = ts.getElementText(c, $row[0].cells[j], j);
|
||||
rowData.raw.push(t); // save original row text
|
||||
// do extract before parsing if there is one
|
||||
if (typeof extractors[j].id === 'undefined') {
|
||||
tx = t;
|
||||
} else {
|
||||
tx = extractors[j].format(t, table, $row[0].cells[j], j);
|
||||
}
|
||||
// allow parsing if the string is empty, previously parsing would change it to zero,
|
||||
// in case the parser needs to extract data from the table cell attributes
|
||||
v = parsers[j].id === 'no-parser' ? '' : parsers[j].format(tx, table, $row[0].cells[j], j);
|
||||
cols.push( c.ignoreCase && typeof v === 'string' ? v.toLowerCase() : v );
|
||||
if ((parsers[j].type || '').toLowerCase() === 'numeric') {
|
||||
// determine column max value (ignore sign)
|
||||
colMax[j] = Math.max(Math.abs(v) || 0, colMax[j] || 0);
|
||||
}
|
||||
t = ts.getElementText(c, $row[0].cells[j], j);
|
||||
rowData.raw.push(t); // save original row text
|
||||
// do extract before parsing if there is one
|
||||
if (typeof extractors[j].id === 'undefined') {
|
||||
tx = t;
|
||||
} else {
|
||||
tx = extractors[j].format(t, table, $row[0].cells[j], j);
|
||||
}
|
||||
// allow parsing if the string is empty, previously parsing would change it to zero,
|
||||
// in case the parser needs to extract data from the table cell attributes
|
||||
v = parsers[j].id === 'no-parser' ? '' : parsers[j].format(tx, table, $row[0].cells[j], j);
|
||||
cols.push( c.ignoreCase && typeof v === 'string' ? v.toLowerCase() : v );
|
||||
if ((parsers[j].type || '').toLowerCase() === 'numeric') {
|
||||
// determine column max value (ignore sign)
|
||||
colMax[j] = Math.max(Math.abs(v) || 0, colMax[j] || 0);
|
||||
}
|
||||
// ensure rowData is always in the same location (after the last column)
|
||||
cols[c.columns] = rowData;
|
||||
cc.normalized.push(cols);
|
||||
}
|
||||
cc.colMax = colMax;
|
||||
// total up rows, not including child rows
|
||||
c.totalRows += cc.normalized.length;
|
||||
// ensure rowData is always in the same location (after the last column)
|
||||
cols[c.columns] = rowData;
|
||||
cc.normalized.push(cols);
|
||||
}
|
||||
cc.colMax = colMax;
|
||||
// total up rows, not including child rows
|
||||
c.totalRows += cc.normalized.length;
|
||||
|
||||
}
|
||||
if (c.showProcessing) {
|
||||
ts.isProcessing(table); // remove processing icon
|
||||
@ -396,7 +392,7 @@
|
||||
function appendToTable(table, init) {
|
||||
var c = table.config,
|
||||
wo = c.widgetOptions,
|
||||
b = table.tBodies,
|
||||
b = c.$tbodies,
|
||||
rows = [],
|
||||
cc = c.cache,
|
||||
n, totalRows, $bk, $tb,
|
||||
@ -412,7 +408,7 @@
|
||||
}
|
||||
for (k = 0; k < b.length; k++) {
|
||||
$bk = $(b[k]);
|
||||
if ($bk.length && !$bk.hasClass(c.cssInfoBlock)) {
|
||||
if ($bk.length) {
|
||||
// get tbody
|
||||
$tb = ts.processTbody(table, $bk, true);
|
||||
n = cc[k].normalized;
|
||||
@ -754,23 +750,23 @@
|
||||
// sort multiple columns
|
||||
function multisort(table) { /*jshint loopfunc:true */
|
||||
var i, k, num, col, sortTime, colMax,
|
||||
cache, order, sort, x, y,
|
||||
rows, order, sort, x, y,
|
||||
dir = 0,
|
||||
c = table.config,
|
||||
cts = c.textSorter || '',
|
||||
sortList = c.sortList,
|
||||
l = sortList.length,
|
||||
bl = table.tBodies.length;
|
||||
bl = c.$tbodies.length;
|
||||
if (c.serverSideSorting || isEmptyObject(c.cache)) { // empty table - fixes #206/#346
|
||||
return;
|
||||
}
|
||||
if (c.debug) { sortTime = new Date(); }
|
||||
for (k = 0; k < bl; k++) {
|
||||
colMax = c.cache[k].colMax;
|
||||
cache = c.cache[k].normalized;
|
||||
rows = c.cache[k].normalized;
|
||||
|
||||
cache.sort(function(a, b) {
|
||||
// cache is undefined here in IE, so don't use it!
|
||||
rows.sort(function(a, b) {
|
||||
// rows is undefined here in IE, so don't use it!
|
||||
for (i = 0; i < l; i++) {
|
||||
col = sortList[i][0];
|
||||
order = sortList[i][1];
|
||||
@ -891,7 +887,7 @@
|
||||
$table.find(c.selectorRemove).remove();
|
||||
// get position from the dom
|
||||
var v, t, row, icell,
|
||||
$tb = $table.find('tbody'),
|
||||
$tb = c.$tbodies,
|
||||
$cell = $(cell),
|
||||
// update cache - format: function(s, table, cell, cellIndex)
|
||||
// no closest in jQuery v1.2.6 - tbdy = $tb.index( $(cell).closest('tbody') ),$row = $(cell).closest('tr');
|
||||
@ -940,7 +936,7 @@
|
||||
$row = $($row).attr('role', 'row'); // make sure we're using a jQuery object
|
||||
var i, j, l, t, v, rowData, cells,
|
||||
rows = $row.filter('tr').length,
|
||||
tbdy = $table.find('tbody').index( $row.parents('tbody').filter(':first') );
|
||||
tbdy = c.$tbodies.index( $row.parents('tbody').filter(':first') );
|
||||
// fixes adding rows to an empty table - see issue #179
|
||||
if (!(c.parsers && c.parsers.length)) {
|
||||
buildParserCache(table);
|
||||
@ -1200,7 +1196,7 @@
|
||||
colgroup = $('<colgroup class="' + ts.css.colgroup + '">');
|
||||
overallWidth = c.$table.width();
|
||||
// only add col for visible columns - fixes #371
|
||||
$(table.tBodies).not('.' + c.cssInfoBlock).find('tr:first').children(':visible').each(function() {
|
||||
c.$tbodies.find('tr:first').children(':visible').each(function() {
|
||||
percent = parseInt( ( $(this).width() / overallWidth ) * 1000, 10 ) / 10 + '%';
|
||||
colgroup.append( $('<col>').css('width', percent) );
|
||||
});
|
||||
|
@ -1146,13 +1146,12 @@ ts.filter = {
|
||||
},
|
||||
findRows: function(table, filters, combinedFilters) {
|
||||
if (table.config.lastCombinedFilter === combinedFilters || !table.config.widgetOptions.filter_initialized) { return; }
|
||||
var len, $rows, rowIndex, tbodyIndex, $tbody, $cells, $cell, columnIndex,
|
||||
var len, norm_rows, $rows, rowIndex, tbodyIndex, $tbody, $cells, $cell, columnIndex,
|
||||
childRow, lastSearch, hasSelect, matches, result, showRow, time, val, indx,
|
||||
notFiltered, searchFiltered, filterMatched, excludeMatch, fxn, ffxn,
|
||||
regex = ts.filter.regex,
|
||||
c = table.config,
|
||||
wo = c.widgetOptions,
|
||||
$tbodies = c.$table.children('tbody'), // target all tbodies #568
|
||||
// data object passed to filters; anyMatch is a flag for the filters
|
||||
data = { anyMatch: false },
|
||||
// anyMatch really screws up with these types of filters
|
||||
@ -1176,14 +1175,14 @@ ts.filter = {
|
||||
// combindedFilters are undefined on init
|
||||
combinedFilters = (filters || []).join('');
|
||||
|
||||
for (tbodyIndex = 0; tbodyIndex < $tbodies.length; tbodyIndex++ ) {
|
||||
if ($tbodies.eq(tbodyIndex).hasClass(c.cssInfoBlock || ts.css.info)) { continue; } // ignore info blocks, issue #264
|
||||
$tbody = ts.processTbody(table, $tbodies.eq(tbodyIndex), true);
|
||||
for (tbodyIndex = 0; tbodyIndex < c.$tbodies.length; tbodyIndex++ ) {
|
||||
$tbody = ts.processTbody(table, c.$tbodies.eq(tbodyIndex), true);
|
||||
// skip child rows & widget added (removable) rows - fixes #448 thanks to @hempel!
|
||||
// $rows = $tbody.children('tr').not(c.selectorRemove);
|
||||
columnIndex = c.columns;
|
||||
// convert stored rows into a jQuery object
|
||||
$rows = $( $.map(c.cache[tbodyIndex].normalized, function(el){ return el[columnIndex].$row.get(); }) );
|
||||
norm_rows = c.cache[tbodyIndex].normalized;
|
||||
$rows = $( $.map(norm_rows, function(el){ return el[columnIndex].$row.get(); }) );
|
||||
|
||||
if (combinedFilters === '' || wo.filter_serversideFiltering) {
|
||||
$rows.removeClass(wo.filter_filteredRow).not('.' + c.cssChildRow).show();
|
||||
@ -1240,7 +1239,7 @@ ts.filter = {
|
||||
// loop through the rows
|
||||
for (rowIndex = 0; rowIndex < len; rowIndex++) {
|
||||
|
||||
data.cacheArray = c.cache[tbodyIndex].normalized[rowIndex];
|
||||
data.cacheArray = norm_rows[rowIndex];
|
||||
|
||||
childRow = $rows[rowIndex].className;
|
||||
// skip child rows & already filtered rows
|
||||
@ -1488,26 +1487,23 @@ ts.filter = {
|
||||
var rowIndex, tbodyIndex, len, row, cache, cell,
|
||||
c = table.config,
|
||||
wo = c.widgetOptions,
|
||||
$tbodies = c.$table.children('tbody'),
|
||||
arry = [];
|
||||
for (tbodyIndex = 0; tbodyIndex < $tbodies.length; tbodyIndex++ ) {
|
||||
if (!$tbodies.eq(tbodyIndex).hasClass(c.cssInfoBlock)) {
|
||||
cache = c.cache[tbodyIndex];
|
||||
len = c.cache[tbodyIndex].normalized.length;
|
||||
// loop through the rows
|
||||
for (rowIndex = 0; rowIndex < len; rowIndex++) {
|
||||
// get cached row from cache.row (old) or row data object (new; last item in normalized array)
|
||||
row = cache.row ? cache.row[rowIndex] : cache.normalized[rowIndex][c.columns].$row[0];
|
||||
// check if has class filtered
|
||||
if (onlyAvail && row.className.match(wo.filter_filteredRow)) { continue; }
|
||||
// get non-normalized cell content
|
||||
if (wo.filter_useParsedData || c.parsers[column].parsed || c.$headers.filter('[data-column="' + column + '"]:last').hasClass('filter-parsed')) {
|
||||
arry.push( '' + cache.normalized[rowIndex][column] );
|
||||
} else {
|
||||
cell = row.cells[column];
|
||||
if (cell) {
|
||||
arry.push( $.trim( cell.getAttribute( c.textAttribute ) || cell.textContent || $(cell).text() ) );
|
||||
}
|
||||
for (tbodyIndex = 0; tbodyIndex < c.$tbodies.length; tbodyIndex++ ) {
|
||||
cache = c.cache[tbodyIndex];
|
||||
len = c.cache[tbodyIndex].normalized.length;
|
||||
// loop through the rows
|
||||
for (rowIndex = 0; rowIndex < len; rowIndex++) {
|
||||
// get cached row from cache.row (old) or row data object (new; last item in normalized array)
|
||||
row = cache.row ? cache.row[rowIndex] : cache.normalized[rowIndex][c.columns].$row[0];
|
||||
// check if has class filtered
|
||||
if (onlyAvail && row.className.match(wo.filter_filteredRow)) { continue; }
|
||||
// get non-normalized cell content
|
||||
if (wo.filter_useParsedData || c.parsers[column].parsed || c.$headers.filter('[data-column="' + column + '"]:last').hasClass('filter-parsed')) {
|
||||
arry.push( '' + cache.normalized[rowIndex][column] );
|
||||
} else {
|
||||
cell = row.cells[column];
|
||||
if (cell) {
|
||||
arry.push( $.trim( cell.getAttribute( c.textAttribute ) || cell.textContent || $(cell).text() ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -149,14 +149,13 @@
|
||||
},
|
||||
|
||||
getRows: function(c, wo) {
|
||||
// the cache may not have a zero index if there are any "info-only" tbodies above the main tbody
|
||||
var cache = c.cache[0].normalized,
|
||||
var norm_rows = c.cache[0].normalized,
|
||||
rows = [];
|
||||
chart_rows = [];
|
||||
chart_categories = [];
|
||||
chart_category = [];
|
||||
|
||||
$.each(cache, function(indx, rowVal) {
|
||||
$.each(norm_rows, function(indx, rowVal) {
|
||||
var i, txt,
|
||||
$tr = rowVal[c.columns].$row,
|
||||
$cells = $tr.children('th,td'),
|
||||
|
@ -54,7 +54,7 @@ ts.grouping = {
|
||||
|
||||
update : function(table, c, wo){
|
||||
if ($.isEmptyObject(c.cache)) { return; }
|
||||
var rowIndex, tbodyIndex, currentGroup, $rows, groupClass, grouping, cache, saveName, direction,
|
||||
var rowIndex, tbodyIndex, currentGroup, $rows, groupClass, grouping, norm_rows, saveName, direction,
|
||||
lang = wo.grouping_language,
|
||||
group = '',
|
||||
savedGroup = false,
|
||||
@ -89,15 +89,15 @@ ts.grouping = {
|
||||
}
|
||||
}
|
||||
for (tbodyIndex = 0; tbodyIndex < c.$tbodies.length; tbodyIndex++) {
|
||||
cache = c.cache[tbodyIndex].normalized;
|
||||
norm_rows = c.cache[tbodyIndex].normalized;
|
||||
group = ''; // clear grouping across tbodies
|
||||
$rows = c.$tbodies.eq(tbodyIndex).children('tr').not('.' + c.cssChildRow);
|
||||
for (rowIndex = 0; rowIndex < $rows.length; rowIndex++) {
|
||||
if ( $rows.eq(rowIndex).is(':visible') ) {
|
||||
// fixes #438
|
||||
if (ts.grouping.types[grouping[1]]) {
|
||||
currentGroup = cache[rowIndex] ?
|
||||
ts.grouping.types[grouping[1]]( c, c.$headers.filter('[data-column="' + column + '"]:last'), cache[rowIndex][column], /date/.test(groupClass) ?
|
||||
currentGroup = norm_rows[rowIndex] ?
|
||||
ts.grouping.types[grouping[1]]( c, c.$headers.filter('[data-column="' + column + '"]:last'), norm_rows[rowIndex][column], /date/.test(groupClass) ?
|
||||
grouping[2] : parseInt(grouping[2] || 1, 10) || 1, group, lang ) : currentGroup;
|
||||
if (group !== currentGroup) {
|
||||
group = currentGroup;
|
||||
|
@ -371,8 +371,7 @@ tsp = ts.pager = {
|
||||
},
|
||||
|
||||
calcFilters: function(table, c) {
|
||||
var tbodyIndex,
|
||||
wo = c.widgetOptions,
|
||||
var wo = c.widgetOptions,
|
||||
p = c.pager,
|
||||
hasFilters = c.$table.hasClass('hasFilters');
|
||||
if (hasFilters && !wo.pager_ajaxUrl) {
|
||||
@ -380,10 +379,8 @@ tsp = ts.pager = {
|
||||
// delayInit: true so nothing is in the cache
|
||||
p.filteredRows = p.totalRows = c.$tbodies.eq(0).children('tr').not( wo.pager_countChildRows ? '' : '.' + c.cssChildRow ).length;
|
||||
} else {
|
||||
// just in case the pager tbody isn't the first tbody
|
||||
tbodyIndex = c.$table.children('tbody').index( c.$tbodies.eq(0) );
|
||||
p.filteredRows = 0;
|
||||
$.each(c.cache[tbodyIndex].normalized, function(i, el) {
|
||||
$.each(c.cache[0].normalized, function(i, el) {
|
||||
p.filteredRows += p.regexRows.test(el[c.columns].$row[0].className) ? 0 : 1;
|
||||
});
|
||||
}
|
||||
@ -898,8 +895,7 @@ tsp = ts.pager = {
|
||||
if ( !$.isEmptyObject(table.config.cache) ) {
|
||||
var i,
|
||||
rows = [],
|
||||
tbodyIndex = c.$table.children('tbody').index( c.$tbodies.eq(0) ),
|
||||
n = table.config.cache[tbodyIndex].normalized;
|
||||
n = table.config.cache[0].normalized;
|
||||
p.totalRows = n.length;
|
||||
for (i = 0; i < p.totalRows; i++) {
|
||||
rows.push(n[i][c.columns].$row);
|
||||
|
@ -31,7 +31,7 @@ var tester = {
|
||||
var i, j = 0, k, l,
|
||||
c = table.config,
|
||||
result = [],
|
||||
b = table.tBodies,
|
||||
b = c.$tbodies,
|
||||
l2 = c.columns;
|
||||
for (k = 0; k < b.length; k++){
|
||||
l = b[k].rows.length;
|
||||
@ -423,7 +423,8 @@ $(function(){
|
||||
expect(4);
|
||||
|
||||
$table1.trigger('sorton', [[[ 0,0 ]]]);
|
||||
tester.cacheCompare( table1, 0, [ 'test1', 'test2', 'test3', '', 'testa', 'testb', 'testc' ], 'from data-attribute' );
|
||||
tester.cacheCompare( table1, 0, [ 'test1', 'test2', 'test3',
|
||||
'testa', 'testb', 'testc' ], 'from data-attribute' );
|
||||
|
||||
$table3.trigger('sorton', [[[ 0,1 ]]]);
|
||||
tester.cacheCompare( table3, 0, [ '', 'a255', 'a102', 'a87', 'a55', 'a43', 'a33', 'a10', 'a02', 'a1' ], 'ignore data-attribute' );
|
||||
@ -442,13 +443,16 @@ $(function(){
|
||||
$table1.trigger('sortReset');
|
||||
|
||||
// lower case because table was parsed before c1.ignoreCase was changed
|
||||
tester.cacheCompare( table1, 'all', [ 'test2', 'x2', 'test1', 'x3', 'test3', 'x1', '', '', 'testb', 'x5', 'testc', 'x4', 'testa', 'x6' ], 'unsorted' );
|
||||
tester.cacheCompare( table1, 'all', [ 'test2', 'x2', 'test1', 'x3', 'test3', 'x1',
|
||||
'testb', 'x5', 'testc', 'x4', 'testa', 'x6' ], 'unsorted' );
|
||||
|
||||
$table1.trigger('sorton', [[[ 0,0 ]]]);
|
||||
tester.cacheCompare( table1, 'all', [ 'test1', 'x3', 'test2', 'x2', 'test3', 'x1', '', '', 'testa', 'x6', 'testb', 'x5', 'testc', 'x4' ], 'ascending sort' );
|
||||
tester.cacheCompare( table1, 'all', [ 'test1', 'x3', 'test2', 'x2', 'test3', 'x1',
|
||||
'testa', 'x6', 'testb', 'x5', 'testc', 'x4' ], 'ascending sort' );
|
||||
|
||||
$table1.trigger('sorton', [[[ 0,1 ]]]);
|
||||
tester.cacheCompare( table1, 'all', [ 'test3', 'x1', 'test2', 'x2', 'test1', 'x3', '', '', 'testc', 'x4', 'testb', 'x5', 'testa', 'x6' ], 'descending sort' );
|
||||
tester.cacheCompare( table1, 'all', [ 'test3', 'x1', 'test2', 'x2', 'test1', 'x3',
|
||||
'testc', 'x4', 'testb', 'x5', 'testa', 'x6' ], 'descending sort' );
|
||||
|
||||
// empty cell position
|
||||
$table3.trigger('sorton', [[[ 0,0 ]]]);
|
||||
@ -569,36 +573,40 @@ $(function(){
|
||||
hl = c1.headerList[1] === nw,
|
||||
p1 = c1.parsers[1].id === 'digit';
|
||||
equal(hc && hd && hl && p1, true, 'testing header cache: updateAll - thead');
|
||||
tester.cacheCompare( table1, 'all', [ 'test3', 1, 'test2', 2, 'test1', 3, '', '', 'testc', 4, 'testb', 5, 'testa', 6 ], 'updateAll - tbody' );
|
||||
tester.cacheCompare( table1, 'all', [ 'test3', 1, 'test2', 2, 'test1', 3,
|
||||
'testc', 4, 'testb', 5, 'testa', 6 ], 'updateAll - tbody' );
|
||||
}]);
|
||||
|
||||
// addRows
|
||||
t = $('<tr class="temp"><td>testd</td><td>7</td></tr>');
|
||||
$table1.find('tbody:last').prepend(t);
|
||||
oldColMax = c1.cache[2].colMax[1];
|
||||
oldColMax = c1.cache[1].colMax[1];
|
||||
$table1.trigger('addRows', [t, true, function(){
|
||||
updateCallback++;
|
||||
equal( oldColMax === 6 && c1.cache[2].colMax[1] === 7, true, 'addRows includes updating colMax value');
|
||||
tester.cacheCompare( table1, 'all', [ 'test3', 1, 'test2', 2, 'test1', 3, '', '', 'testd', 7, 'testc', 4, 'testb', 5, 'testa', 6 ], 'addRows method' );
|
||||
equal( oldColMax === 6 && c1.cache[1].colMax[1] === 7, true, 'addRows includes updating colMax value');
|
||||
tester.cacheCompare( table1, 'all', [ 'test3', 1, 'test2', 2, 'test1', 3,
|
||||
'testd', 7, 'testc', 4, 'testb', 5, 'testa', 6 ], 'addRows method' );
|
||||
}]);
|
||||
|
||||
// updateCell
|
||||
t = $table1.find('td:contains("7")');
|
||||
t.html('-8');
|
||||
oldColMax = c1.cache[2].colMax[1];
|
||||
oldColMax = c1.cache[1].colMax[1];
|
||||
$table1.trigger('updateCell', [t[0], true, function(){
|
||||
updateCallback++;
|
||||
equal( oldColMax === 7 && c1.cache[2].colMax[1] === 8, true, 'updateCell includes updating colMax value');
|
||||
tester.cacheCompare( table1, 'all', [ 'test3', 1, 'test2', 2, 'test1', 3, '', '', 'testd', -8, 'testc', 4, 'testb', 5, 'testa', 6 ], 'updateCell method' );
|
||||
equal( oldColMax === 7 && c1.cache[1].colMax[1] === 8, true, 'updateCell includes updating colMax value');
|
||||
tester.cacheCompare( table1, 'all', [ 'test3', 1, 'test2', 2, 'test1', 3,
|
||||
'testd', -8, 'testc', 4, 'testb', 5, 'testa', 6 ], 'updateCell method' );
|
||||
}]);
|
||||
|
||||
// update
|
||||
$table1.find('tr.temp').remove();
|
||||
oldColMax = c1.cache[2].colMax[1];
|
||||
oldColMax = c1.cache[1].colMax[1];
|
||||
$table1.trigger('update', [true, function(){
|
||||
updateCallback++;
|
||||
equal( oldColMax === 8 && c1.cache[2].colMax[1] === 6, true, 'update includes updating colMax value');
|
||||
tester.cacheCompare( table1, 'all', [ 'test3', 1, 'test2', 2, 'test1', 3, '', '', 'testc', 4, 'testb', 5, 'testa', 6 ], 'update method' );
|
||||
equal( oldColMax === 8 && c1.cache[1].colMax[1] === 6, true, 'update includes updating colMax value');
|
||||
tester.cacheCompare( table1, 'all', [ 'test3', 1, 'test2', 2, 'test1', 3,
|
||||
'testc', 4, 'testb', 5, 'testa', 6 ], 'update method' );
|
||||
}]);
|
||||
|
||||
$table5
|
||||
|
Loading…
Reference in New Issue
Block a user