Exinaus писал(а):<skip>
Поэтому я решил почитать документацию о создании собственных виджетов, и вот вышло вот такое:
Читать дальше
Код: Выделить всё<script type="text/javascript" id="js">
$.tablesorter.addWidget({
id: "counter",
priority: 15,
options: {
sort_start : 1,
sort_header : '#',
sort_align : "center",
},
init: function(table, tW, c, wo) {
if (c.theme == 'jui') {
// add <th> in <thead> for counter
$(table).find("thead tr").filter(':visible').each(function() {
$( this ).prepend( '<th align="' + wo.sort_align + '" class="tablesorter-counter-temp sorter-false">' + wo.sort_header + '</th>' );
});
//add <td> for every visible row of table
$(table).find("tbody tr").filter(':visible').each(function(i) {
$( this ).prepend( '<td align="' + wo.sort_align + '" class="tablesorter-counter">' + (i+wo.sort_start) + '</td>' );
});
// in case if we have <tfoot>
$(table).find("tfoot tr").filter(':visible').each(function() {
$( this ).prepend( '<th align="' + wo.sort_align + '" class="tablesorter-counter-temp">' + wo.sort_header + '</th>' );
});
}
},
format: function(table, c, wo) {
if (c.theme == 'jui') {
$(table).find("td.tablesorter-counter").filter(':visible').each(function(j) {
$(this).text(j+wo.sort_start);
});
var display_class = $(table).find('th:last-child').attr('class');
$(table).find('th.tablesorter-counter-temp').filter(':visible').each(function() {
$(this).removeClass().addClass( display_class ).removeClass( "ui-state-active sorter-false" ).addClass('sorter-false');
});
}
}
});
</script>
<skip>
Замечательный виджет. Вот только в таком виде не применим к большинству таблиц модуля. Но если заменить
Код: Выделить всёvar display_class = $(table).find('th:last-child').attr('class');
на
Код: Выделить всёvar display_class = $(table).find('th:nth-child(2)').attr('class');
то всё становится просто замечательно, так как для столбца счётчика используется классы не последнего элемента, а первого. А первый элемент (вроде как) всех таблиц у нас не меняется.
Ещё раз спасибо за виджет

И в довесок, для использования данного виджета отлично подходят следующие таблицы:
Код: Выделить всё $("#best_counter")
.add("#overall")
.add("#battel")
.add("#famepoints")
.add("#active_main")
.add("#all_medals_stat")
.add("#rating_all")
.add("#perform_all").tablesorter({widgets: ['uitheme','stickyheaders','zebra','counter']});