I am using a dropdown filter to filter a table column with numeric values. I read all the documentation on tablesorter, but I am not sure how to get an exact match on the number. When I select 4 in column 8 (zero-based) it shows 4,14 and 42.
Any ideas? I think I need to parse the values but I am not sure how to do it.
This is the script:
<script>
$(document).ready(function(){
var $table = $('table').tablesorter({
sortList: [[0,0]] ,
widgets: ["filter"],
widgetOptions: {
filter_columnFilters: false,
filter_reset: '.reset'
},
headers: {
// Spalte startet mit 0
0: {sorter:false},
1: {sorter:false},
2: {sorter:false},
3: {sorter:false},
4: {sorter:false},
5: {sorter:false},
6: {sorter:false},
7: {sorter:false},
8: {filter: "digit"}
}
});
$.tablesorter.filter.bindSearch( $table, $('.search') );
});
</script>
And this is the dropdown list:
<label>Liga</label>
<select class="search" style="width:175px;" data-column="8">
<option selected disabled hidden value=''></option>
<?php
$sqlfile = '../sql/leagues.sql';
$sqlcont = file_get_contents($sqlfile);
$league_query = mysql_query($sqlcont) or die("Anfrage sql nicht erfolgreich");
while ($filter = mysql_fetch_array($league_query)){
echo "<option value='".$filter['LID']."'>".$filter['LID']."</option>";
}?>
</select>
And finally the tableheaders:
<thead>
<tr>
<th>Datum</th>
<th>Uhrzeit</th>
<th>Spielklasse</th>
<th>Liga</th>
<th>Team A</th>
<th>Team B</th>
<th>Ergebnis</th>
<th>Auswertung</th>
<th>SID</th>
</tr>
</thead>
The filter widget is set up by default to match results. If you want to exactly match a result, add an equal sign (=
) or quote ("
or '
) to the end of the query. Try this demo & use 10=
in the second column to only show values of 10
.
On this demo page, a full list of filter widget search types are available.
If you want the results to always be an exact match, then check out this demo that shows how to use the filter_functions
option to always return an exact match - that code should work for both text and numbers, if not, then change the ===
to ==
as follows:
filter_functions : {
// Exact match only
1 : function(e, n, f, i, $r) {
return e == f;
}
}