I have a table which has a thead section and a tbody section. I'm using jQuery each to find and count all THs in a table. This works fine. But at the same time I want to check if the TDs of the THs in the tbody is containing any input elements.
Here is what I have so far:
jQuery('#' + _target).each(function () {
var $table = jQuery(this);
var i = 0;
jQuery('th', $table).each(function (column) {
if (jQuery(this).find("input")) {
dataTypes[i] = { "sSortDataType": "input" }
}
else {
dataTypes[i] = { "sSortDataType": "html" }
}
i++;
});
});
I hope this is enough information for you to help me out?
dataTypes = $('#' + _target + ' th').map(function(i, th) {
var $table = $(th).closest('table');
var pos = $table.index(th) + 1;
return { "sSortDataType": $table.find('td:nth-child('+pos+')').is(':has(input)') ? 'input' : 'html' };
});
Edit: if you are running this on a single table (in which case the each call in the original example does not make much sense), it gets simpler:
dataTypes = $('#' + _target + ' th').map(function(pos, th) {
return { "sSortDataType": $(th).closest('table').find('td:nth-child('+(pos+1)+')').is(':has(input)') ? 'input' : 'html' };
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With