tablesort.js (tablesort-5.2.1) | : | tablesort.js (tablesort-5.3.0) | ||
---|---|---|---|---|
skipping to change at line 26 | skipping to change at line 26 | |||
if (!window.CustomEvent || typeof window.CustomEvent !== 'function') { | if (!window.CustomEvent || typeof window.CustomEvent !== 'function') { | |||
evt = document.createEvent('CustomEvent'); | evt = document.createEvent('CustomEvent'); | |||
evt.initCustomEvent(name, false, false, undefined); | evt.initCustomEvent(name, false, false, undefined); | |||
} else { | } else { | |||
evt = new CustomEvent(name); | evt = new CustomEvent(name); | |||
} | } | |||
return evt; | return evt; | |||
}; | }; | |||
var getInnerText = function(el) { | var getInnerText = function(el,options) { | |||
return el.getAttribute('data-sort') || el.textContent || el.innerText || ''; | return el.getAttribute(options.sortAttribute || 'data-sort') || el.textConte | |||
nt || el.innerText || ''; | ||||
}; | }; | |||
// Default sort method if no better sort method is found | // Default sort method if no better sort method is found | |||
var caseInsensitiveSort = function(a, b) { | var caseInsensitiveSort = function(a, b) { | |||
a = a.trim().toLowerCase(); | a = a.trim().toLowerCase(); | |||
b = b.trim().toLowerCase(); | b = b.trim().toLowerCase(); | |||
if (a === b) return 0; | if (a === b) return 0; | |||
if (a < b) return 1; | if (a < b) return 1; | |||
skipping to change at line 175 | skipping to change at line 175 | |||
if (!sortMethod) { | if (!sortMethod) { | |||
var cell; | var cell; | |||
while (items.length < 3 && i < that.table.tBodies[0].rows.length) { | while (items.length < 3 && i < that.table.tBodies[0].rows.length) { | |||
if(columnKey) { | if(columnKey) { | |||
cell = getCellByKey(that.table.tBodies[0].rows[i].cells, columnKey); | cell = getCellByKey(that.table.tBodies[0].rows[i].cells, columnKey); | |||
} else { | } else { | |||
cell = that.table.tBodies[0].rows[i].cells[column]; | cell = that.table.tBodies[0].rows[i].cells[column]; | |||
} | } | |||
// Treat missing cells as empty cells | // Treat missing cells as empty cells | |||
item = cell ? getInnerText(cell) : ""; | item = cell ? getInnerText(cell,that.options) : ""; | |||
item = item.trim(); | item = item.trim(); | |||
if (item.length > 0) { | if (item.length > 0) { | |||
items.push(item); | items.push(item); | |||
} | } | |||
i++; | i++; | |||
} | } | |||
skipping to change at line 231 | skipping to change at line 231 | |||
noSorts[totalRows] = item; | noSorts[totalRows] = item; | |||
} else { | } else { | |||
if (columnKey) { | if (columnKey) { | |||
cell = getCellByKey(item.cells, columnKey); | cell = getCellByKey(item.cells, columnKey); | |||
} else { | } else { | |||
cell = item.cells[that.col]; | cell = item.cells[that.col]; | |||
} | } | |||
// Save the index for stable sorting | // Save the index for stable sorting | |||
newRows.push({ | newRows.push({ | |||
tr: item, | tr: item, | |||
td: cell ? getInnerText(cell) : '', | td: cell ? getInnerText(cell,that.options) : '', | |||
index: totalRows | index: totalRows | |||
}); | }); | |||
} | } | |||
totalRows++; | totalRows++; | |||
} | } | |||
// Before we append should we reverse the new array or not? | // Before we append should we reverse the new array or not? | |||
// If we reverse, the sort needs to be `anti-stable` so that | // If we reverse, the sort needs to be `anti-stable` so that | |||
// the double negatives cancel out | // the double negatives cancel out | |||
if (sortOrder === 'descending') { | if (sortOrder === 'descending') { | |||
newRows.sort(stabilize(sortFunction, true)); | newRows.sort(stabilize(sortFunction, true)); | |||
End of changes. 3 change blocks. | ||||
4 lines changed or deleted | 5 lines changed or added |