(function ($) {
$.fn.extend({
tableAddCounter: function (options) {
var defaults = {
title: '#',
start: 1,
id: false,
cssClass: false
};
var options = $.extend({}, defaults, options);
return $(this).each(function () {
if ($(this).is('table')) {
if (!options.title) options.title = '';
$('th:first-child, thead td:first-child', this).each(function () {
var tagName = $(this).prop('tagName');
$(this).before('<' + tagName + ' rowspan="' + $('thead tr').length + '" class="' + options.cssClass + '" id="' + options.id + '">' + options.title + '</' + tagName + '>');
});
$('tbody td:first-child', this).each(function (i) {
$(this).before('<td>' + (options.start + i) + '</td>');
});
}
});
}
});
})(jQuery);