MediaWiki:Common.js: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Rbritt (Diskussion | Beiträge) Keine Bearbeitungszusammenfassung Markierung: Zurückgesetzt |
Rbritt (Diskussion | Beiträge) Änderung 524 von Rbritt (Diskussion) rückgängig gemacht. Markierung: Rückgängigmachung |
||
| Zeile 1: | Zeile 1: | ||
$(function() { | $(function() { | ||
// | // Wir warten kurz, bis MediaWiki die Tabelle fertig gerendert hat | ||
mw.loader.using(['jquery.tablesorter'], function() { | mw.loader.using(['jquery.tablesorter'], function() { | ||
$('table.filterable').each(function() { | $('table.filterable').each(function() { | ||
var $table = $(this); | var $table = $(this); | ||
// Header | // Wir suchen alle echten Datenzeilen (ignorieren den Header) | ||
var $ | var $rows = $table.find('tbody tr').not(function() { | ||
return $(this).find('th').length > 0; | |||
}); | |||
var $headerRow = $table.find('tr').first(); | |||
} | var $filterRow = $('<tr class="filter-row"></tr>'); | ||
var $headerRow = $ | |||
var $filterRow = $('<tr class="filter-row | |||
$headerRow.find('th').each(function(index) { | $headerRow.find('th').each(function(index) { | ||
var $filterCell = $('<th style="background:#f2f2f2 | var $filterCell = $('<th style="background:#f2f2f2;"></th>'); | ||
var $select = $('<select style="width: 100%; | var $select = $('<select style="width: 100%; min-width: 60px;"><option value="">(Alle)</option></select>'); | ||
// | // Klick-Event stoppen, damit die Tabelle nicht sortiert wird, wenn man das Menü öffnet | ||
$select.on('click', function(e) { | $select.on('click mousedown', function(e) { | ||
e.stopPropagation(); | e.stopPropagation(); | ||
}); | }); | ||
// | // Werte sammeln | ||
var values = []; | var values = []; | ||
$ | $rows.each(function() { | ||
var text = $(this).text().trim(); | var text = $(this).find('td').eq(index).text().trim(); | ||
if (text !== "" && $.inArray(text, values) === -1) { | if (text !== "" && $.inArray(text, values) === -1) { | ||
values.push(text); | values.push(text); | ||
| Zeile 35: | Zeile 31: | ||
}); | }); | ||
// Sortieren und hinzufügen | |||
values.sort().forEach(function(val) { | values.sort().forEach(function(val) { | ||
$select.append($('<option></option>').val(val).text(val)); | $select.append($('<option></option>').val(val).text(val)); | ||
| Zeile 40: | Zeile 37: | ||
$select.on('change', function() { | $select.on('change', function() { | ||
filterTable($table); | |||
}); | }); | ||
| Zeile 47: | Zeile 44: | ||
}); | }); | ||
// | // Filterzeile nach dem Header einfügen | ||
$ | $headerRow.after($filterRow); | ||
}); | }); | ||
}); | }); | ||
function | function filterTable($table) { | ||
var $rows = $table.find('tbody tr').not('.filter-row'); | var $rows = $table.find('tbody tr').not('.filter-row').not(function() { | ||
return $(this).find('th').length > 0; | |||
}); | |||
var $selects = $table.find('.filter-row select'); | var $selects = $table.find('.filter-row select'); | ||
$rows.each(function() { | $rows.each(function() { | ||
var $row = $(this); | var $row = $(this); | ||
var | var showRow = true; | ||
$selects.each(function(index) { | $selects.each(function(index) { | ||
| Zeile 68: | Zeile 64: | ||
if (filterValue !== "" && cellValue !== filterValue) { | if (filterValue !== "" && cellValue !== filterValue) { | ||
showRow = false; | |||
return false; | return false; | ||
} | } | ||
}); | }); | ||
$row.toggle(showRow); | |||
$row.toggle( | |||
}); | }); | ||
} | } | ||
}); | }); | ||
Version vom 24. Februar 2026, 08:14 Uhr
$(function() {
// Wir warten kurz, bis MediaWiki die Tabelle fertig gerendert hat
mw.loader.using(['jquery.tablesorter'], function() {
$('table.filterable').each(function() {
var $table = $(this);
// Wir suchen alle echten Datenzeilen (ignorieren den Header)
var $rows = $table.find('tbody tr').not(function() {
return $(this).find('th').length > 0;
});
var $headerRow = $table.find('tr').first();
var $filterRow = $('<tr class="filter-row"></tr>');
$headerRow.find('th').each(function(index) {
var $filterCell = $('<th style="background:#f2f2f2;"></th>');
var $select = $('<select style="width: 100%; min-width: 60px;"><option value="">(Alle)</option></select>');
// Klick-Event stoppen, damit die Tabelle nicht sortiert wird, wenn man das Menü öffnet
$select.on('click mousedown', function(e) {
e.stopPropagation();
});
// Werte sammeln
var values = [];
$rows.each(function() {
var text = $(this).find('td').eq(index).text().trim();
if (text !== "" && $.inArray(text, values) === -1) {
values.push(text);
}
});
// Sortieren und hinzufügen
values.sort().forEach(function(val) {
$select.append($('<option></option>').val(val).text(val));
});
$select.on('change', function() {
filterTable($table);
});
$filterCell.append($select);
$filterRow.append($filterCell);
});
// Filterzeile nach dem Header einfügen
$headerRow.after($filterRow);
});
});
function filterTable($table) {
var $rows = $table.find('tbody tr').not('.filter-row').not(function() {
return $(this).find('th').length > 0;
});
var $selects = $table.find('.filter-row select');
$rows.each(function() {
var $row = $(this);
var showRow = true;
$selects.each(function(index) {
var filterValue = $(this).val();
var cellValue = $row.find('td').eq(index).text().trim();
if (filterValue !== "" && cellValue !== filterValue) {
showRow = false;
return false;
}
});
$row.toggle(showRow);
});
}
});