J'essaie de filtrer une table en utilisant la classe des boîtes select2 et multiple.Comment filtrer une table en utilisant plusieurs cases select2?
Tableau HTML
<table class="table">
<tbody>
<tr class="kanban-event Austin">
<td>...</td>
</tr>
<tr class="csm-event Charlotte">
<td>...</td>
</tr>
<tr class="cal-event Charlotte">
<td>...</td>
</tr>
<tr class="cspo-event Austin">
<td>...</td>
</tr>
<tr class="cal-event Raleigh">
<td>...</td>
</tr>
<tr class="kanban Charlotte">
<td>...</td>
</tr>
<tr class="cspo-event Austin">
<td>...</td>
</tr>
<tr class="csm-event Charlotte">
<td>...</td>
</tr>
<tr class="safe-event Austin">
<td>...</td>
</tr>
<tr class="cspo-event Raleigh">
<td>...</td>
</tr>
<tr class="csm-event Charlotte">
<td>...</td>
</tr>
<tr class="csm-event Raleigh">
<td>...</td>
</tr>
</tbody>
</table>
Sélectionnez HTML
<select id="location">
<option value="all">All Locations ...</option>
<option value="Austin">Austin, TX</option>
<option value="Charlotte">Charlotte, NC</option>
<option value="Raleigh">Raleigh, NC</option>
</select>
<select id="course">
<option value="all">All Courses ...</option>
<option value="csm">Certified Scrum Master (CSM)</option>
<option value="cspo">Certified Scrum Product Owner (CSPO)</option>
<option value="cal">Certified Agile Leadership (CAL)</option>
<option value="safe">Scaled Agile Framework (SAFe®)</option>
<option value="kanban">Kanban</option>
</select>
actuelle JS
jQuery(function() {
jQuery("#course").on("select2-selecting", function (evt) {
// console.log(evt.val);
// console.log(jQuery('#events-table tr:not(".'+evt.val+'-event")'));
jQuery('#events-table tr').show();
jQuery('#events-table thead tr').show();
jQuery('#events-table tr:not(".'+evt.val+'-event")').hide();
jQuery('#events-table thead tr').show();
if (evt.val == '') {
jQuery('#events-table tr').show();
jQuery('#events-table thead tr').show();
}
});
jQuery("#location").on("select2-selecting", function (evt) {
// console.log(evt.val);
// console.log(jQuery('#events-table tr:not(".'+evt.val+'")'));
jQuery('#events-table tr').show();
jQuery('#events-table thead tr').show();
jQuery('#events-table tr:not(".'+evt.val+'")').hide();
jQuery('#events-table thead tr').show();
if (evt.val == '') {
jQuery('#events-table tr').show();
jQuery('#events-table thead tr').show();
}
});
});
Les JS actuels permettent s filtrage à la table, mais ne gère qu'un seul filtre à la fois. Je me demande comment puis-je faire travailler les sélections ensemble, par exemple avoir le spectacle CSM Events in Austin et tout le reste cacher?
Merci d'avance.
Edit: Voici un violon https://jsfiddle.net/5202jsax/6/
S'il vous plaît ajouter jsfiddle, ce serait bien. – Webinion
@PandhiBhaumik - Fiddle ajouté –