MediaWiki:Common.js: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Rbritt (Diskussion | Beiträge) Keine Bearbeitungszusammenfassung |
Rbritt (Diskussion | Beiträge) Keine Bearbeitungszusammenfassung |
||
| Zeile 1: | Zeile 1: | ||
$(function() { | $(function() { | ||
$('table.filterable').each(function() { | $('table.filterable').each(function() { | ||
var $table = $(this); | var $table = $(this); | ||
var $headerRow = $table.find('tr').first(); | var $headerRow = $table.find('tr').first(); | ||
var $filterRow = $('<tr class="filter-row"></tr>'); | var $filterRow = $('<tr class="filter-row"></tr>'); | ||
var $rows = $table.find('tbody > tr').not(':first'); | |||
$headerRow.find('th').each(function(index) { | |||
$headerRow.find('th').each(function() { | |||
var $filterCell = $('<th></th>'); | var $filterCell = $('<th></th>'); | ||
var $ | var $select = $('<select style="width: 100%;"><option value="">Alle</option></select>'); | ||
// Eindeutige Werte aus der Spalte sammeln | |||
var values = []; | |||
$rows.each(function() { | |||
var val = $(this).find('td').eq(index).text().trim(); | |||
if (val && $.inArray(val, values) === -1) { | |||
values.push(val); | |||
} | |||
}); | |||
// Werte sortieren und als Optionen hinzufügen | |||
values.sort().forEach(function(val) { | |||
$select.append($('<option></option>').val(val).html(val)); | |||
}); | |||
$ | $select.on('change', function() { | ||
filterTable($table); | filterTable($table); | ||
}); | }); | ||
$filterCell.append($ | $filterCell.append($select); | ||
$filterRow.append($filterCell); | $filterRow.append($filterCell); | ||
}); | }); | ||
$headerRow.after($filterRow); | $headerRow.after($filterRow); | ||
}); | }); | ||
function filterTable($table) { | function filterTable($table) { | ||
var $rows = $table.find('tr').not(':first').not('.filter-row'); | var $rows = $table.find('tbody > tr').not(':first').not('.filter-row'); | ||
var $ | var $selects = $table.find('.filter-row select'); | ||
$rows.each(function() { | $rows.each(function() { | ||
| Zeile 42: | Zeile 43: | ||
var showRow = true; | var showRow = true; | ||
$ | $selects.each(function(index) { | ||
var filterValue = $(this).val | var filterValue = $(this).val(); | ||
var cellValue = $row.find('td').eq(index).text(). | var cellValue = $row.find('td').eq(index).text().trim(); | ||
if (filterValue && cellValue | if (filterValue !== "" && cellValue !== filterValue) { | ||
showRow = false; | showRow = false; | ||
return false; | return false; | ||
} | } | ||
}); | }); | ||
Version vom 24. Februar 2026, 08:04 Uhr
$(function() {
$('table.filterable').each(function() {
var $table = $(this);
var $headerRow = $table.find('tr').first();
var $filterRow = $('<tr class="filter-row"></tr>');
var $rows = $table.find('tbody > tr').not(':first');
$headerRow.find('th').each(function(index) {
var $filterCell = $('<th></th>');
var $select = $('<select style="width: 100%;"><option value="">Alle</option></select>');
// Eindeutige Werte aus der Spalte sammeln
var values = [];
$rows.each(function() {
var val = $(this).find('td').eq(index).text().trim();
if (val && $.inArray(val, values) === -1) {
values.push(val);
}
});
// Werte sortieren und als Optionen hinzufügen
values.sort().forEach(function(val) {
$select.append($('<option></option>').val(val).html(val));
});
$select.on('change', function() {
filterTable($table);
});
$filterCell.append($select);
$filterRow.append($filterCell);
});
$headerRow.after($filterRow);
});
function filterTable($table) {
var $rows = $table.find('tbody > tr').not(':first').not('.filter-row');
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);
});
}
});