Skip to content
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

Change widgetOptions (or filter all or only one) #490

Closed
SilverSilencer opened this issue Jan 29, 2014 · 6 comments
Closed

Change widgetOptions (or filter all or only one) #490

SilverSilencer opened this issue Jan 29, 2014 · 6 comments

Comments

@SilverSilencer
Copy link

I made two fields (input text and select), where I can write search text and select which column should be filtered. That works great, but I don't know how to add option to search all fields (with OR not AND).

Is there any way to change widgetOptions (maybe that would work if I change filter_anyMatch to true when user decides to seaerch all fields not only one). This is what I have so far:

wherewesearch = document.getElementById("dropdownsearch").value;
whatwesearch = document.getElementById("filtersearch").value;
$('.table').trigger('filterReset');
var columns = [];
if (selectedvalue == "0") {
// What to do here? To enable search all fields?
} else {
columns[wherewesearch] = whatwesearch;
$('.table').trigger('search', [columns]);
}

@Mottie
Copy link
Owner

Mottie commented Jan 29, 2014

Hi @SilverSilencer!

Right now there isn't an easy way to make any match work as you describe. But good news is I've been working on it so that what you are describing is possible. All I would need to do is make a few tweaks to make the input switch dynamically from searching all columns to a selected column.

I wonder though, should we make it easier for the user, so they don't need to use an attached select? Maybe have them include a prefix, something like all:, to have the filter search all columns (e.g. all:banana to find "banana" in any column)?

I'm not sure if that would be intuitive...

@SilverSilencer
Copy link
Author

Yeah, that would be great. Easy way is always welcomed, but if it's limited usage, it's better to do both if it's possible, otherwise it's better to use more extended way.

@Mottie Mottie closed this as completed in 55e5bdb Feb 19, 2014
@Mottie
Copy link
Owner

Mottie commented Feb 19, 2014

Check out the new external inputs demo... the top search has a column/all column selector.

@SilverSilencer
Copy link
Author

I just can get this to work. When I use this no matter what I write all fields are shown and are not filtered.

At my first code I changed
if (selectedvalue == "0") {
to
if (selectedvalue == "all") {

and then added:
$('.table').trigger('search', [['', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', whatwesearch]]);

Because I have 21 columns. And whatever I write all rows are snown when I use option with value "all".

@Mottie
Copy link
Owner

Mottie commented Feb 20, 2014

Hi @SilverSilencer!

Here is a basic demo to show you it works:

HTML

<button>Find "10"</button>

<table class="tablesorter">
...
</table>
$('table').tablesorter({
    theme: 'blue',
    widgets: ['zebra', 'filter']
});

$('button').on('click', function(){
    var filters = [];
    // the table only has 4 columns, so set the search on the 5th
    // to match in any column; remember this number is zero-based
    filters[4] = "10";
    $('table').trigger('search', [ filters ]);
});

If you share the code you are using, I can try to help troubleshoot the problem.

@SilverSilencer
Copy link
Author

I think I got it to work now. I had to remove class "search" from input and change $('.table') to $('table'). Looks like it works great now :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants