JavaScript/jQuery: colMax()
Retrieve max value of a given column of table cells:
function colMax(parent, colIndex) {
var max = 0,
sorted = $(‘td:nth-child(’ + colIndex + ‘)’, parent).get().sort(function(a, b) {
return b - a;
});max = parseInt(sorted.length > 0 ? $(sorted[sorted.length - 1]).text() : 0);
return !isNaN(max) ? max : 0;
}
var max = colMax($(‘.table tbody’)[0], 1);
- Using the cell parent, get and sort the cells.
- Check length and return top cell.
Wednesday Jun 22nd