-
Notifications
You must be signed in to change notification settings - Fork 754
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
External select #671
Comments
Hi @Tedd22! You can use the internal filter widget // get an array of all table cell contents for a table column
var table = $('table')[0],
column = 1,
array = $.tablesorter.filter.getOptions(table, column);
// get unique elements and sort the list
arry = $.grep(arry, function(value, indx) {
return $.inArray(value, arry) === indx;
}).sort(); Then you can apply that to your select and bind to it using the |
Thanks for your instructions Mottie ! I have prepared the ground here http://jsfiddle.net/Ted22/LR3sX/58/ but I need your help to make it working... Many thanks in advance Mottie, you're the king ! And in my country, Belgium, we know what it is ;-) Ted |
Hi Ted! Sorry, I forgot there are two functions:
I should probably rename those functions so they can better describe what they do. Anyway, here is a working demo: $(function () {
var $t = $("#myTable").tablesorter({
theme: 'blue',
widgets: ['filter'],
widgetOptions: {
filter_columnFilters: false,
filter_external: $('#select1')
}
});
// get an array of all table cell contents for a table column
var arry = $.tablesorter.filter.getOptionSource($t[0], 1);
$('#select1').append('<option>' + arry.join('</option><option>') + '</option>');
}); Also note that I had to modify the external selector by adding a <select id="select1" data-column="1">
<option value="">First Name</option>
</select> |
It works like a charm, many thanks Mottie ! Now, I try to freeze the external selects with stickyheaders, but I don't know the right way. See it here : http://jsfiddle.net/Ted22/LR3sX/62/ Thanks in advance ! Ted |
Now it's getting a bit more complicated. If you use the If you don't plan on supporting older browsers (IE9+), the easiest solution would be to use the HTML <table id="myTable" class="tablesorter">
<caption class="menubar">
<select id="select1" data-column="0">
<option value="">–Last Name–</option>
</select>
<select id="select2" data-column="1">
<option value="">–First Name–</option>
</select>
</caption>
<thead>
<!-- ... -->
</thead>
<tbody>
<!-- ... -->
</tbody>
</table> Script $(function () {
var $t = $("#myTable").tablesorter({
theme: 'blue',
widgets: ['filter', 'cssStickyHeaders'],
widgetOptions: {
filter_columnFilters: false,
filter_external: $('#select1, #select2'),
cssStickyHeaders_addCaption: true,
}
});
function getSource(indx) {
var arry = $.tablesorter.filter.getOptionSource($t[0], indx);
return arry.map(function(obj) {
return obj.text;
});
}
// get an array of all table cell contents for a table column
$('#select1').append('<option>' + getSource(0).join('</option><option>') + '</option>');
// get an array of all table cell contents for a table column
$('#select2').append('<option>' + getSource(1).join('</option><option>') + '</option>');
}); If that doesn't work for you, then maybe we can think of something different. Updated (2018-07-20) because |
Thanks Mottie. I finally found a solution with css positionning properties. See it here : http://jsfiddle.net/Ted22/LR3sX/65/ Not better than your solution but it works with old browsers. Ted |
I'm guessing this issue has been resolved, so I'm going to close it. If you continue to have problems, please feel free to continue this discussion. |
Please see issue #702 & update to v2.17.7 if you are seeing this break in v2.17.6. |
Hey @Mottie it looks like your fiddle is broken. It is pulling all of the items from the column as [Object object] which is a rather unhelpful datatype for sorting. Shouldn't be too bad of a fix. |
Updated! http://jsfiddle.net/Mottie/ahk7cgqp/ |
The |
Hi,
I'd like to use external select (dropdown list), like external input. The select should work exactly the same way select does inside the table. It should list all the values of the column.
Is it a way to do this ?
Thanks in advance !
Ted
The text was updated successfully, but these errors were encountered: