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

Range filters #66

Open
fr0z3nfyr opened this issue Jun 29, 2015 · 11 comments
Open

Range filters #66

fr0z3nfyr opened this issue Jun 29, 2015 · 11 comments

Comments

@fr0z3nfyr
Copy link

How can I get range filters to work? I have two inputs for a column to do a range search, see image for sample. when I check in console, i get sSearch_0, sSearch_1, sSearch_2, sSearch_3 in config.

One, why is sSearch3 required if there is no search on the last column. I think I have to check DT also to see if that is a mandate.
Two, I'm using YADCF for column filtering, so for the range filter, the searched range returns 0 rows. Probably, the query to DB is being passed incorrectly. How can I fix this? I'm supposing that the range filters for dates will also misbehave, I haven't tested.
sample

@tigrang
Copy link
Owner

tigrang commented Jun 30, 2015

Hey @fr0z3nfyr, sorry I've been busy. I'll take a look either in the next an hour or so, if not, then tomorrow.

@tigrang
Copy link
Owner

tigrang commented Jun 30, 2015

Can you paste your component config and the js settings you're initializing jquery datatables with?

For range filter, you'll need to use a custom search method on that column. It looks like sSearch0 would be in a format like "fromvalue-tovalue" so the custom find would need to explode on that separator to get the two values.

Custom find works like this:

public $components = [
    'DataTable.DataTable' => [
        'User' => [
            'columns' => [
                'id' => ['bSearchable'  => 'rangeFilter'], 
                'username', 
                'email'
              ],
        ],
];

In your model add a function like:

public function rangeFilter($column, $searchTerm, $columnSearchTerm, $config) {
    // you can then check $columnSearchTerm and add conditions on `$config->conditions`
}

But yadcf states that it supports only server-side processing (1.10.0 +) which my plugin doesn't handle. I don't know how you have any of this working.

@fr0z3nfyr
Copy link
Author

Hey sorry, I was sick with a fever, just checked your comment. I will post my component settings as soon as I get back on the project. Meanwhile you can check my interaction with author of yadcf @ http://stackoverflow.com/questions/31045543/ I too was a little confused originally but somehow (probably by fluke) got it working this far. I will also post an implementation for Daniel(yadcf author) on his thread(see comments on answer on SO link).

@destinydriven
Copy link
Contributor

I would like to implement range filters similar to what is used here http://www.alpha.mobotrix.com/cake/users but not necessarily using YADCF.

@tigrang
Copy link
Owner

tigrang commented Apr 3, 2016

@destinydriven the backend is setup for this but you need to manually add the column filters and call the filter function with jquery plugin. See https://legacy.datatables.net/examples/api/multi_filter.html

The important bit is calling

$("tfoot input").keyup( function () {
    /* Filter on the column (the index) of this element */
    oTable.fnFilter( this.value, $("tfoot input").index(this) );
} );

where otable is a reference to the datatables object for your specific table.

@destinydriven
Copy link
Contributor

@tigrang So I need to override render() in the Helper so I can inject the footer into the table?

@tigrang
Copy link
Owner

tigrang commented Apr 4, 2016

@destinydriven check this gist out for an exmaple. https://gist.github.com/tigrang/e6b9d53a407280f791f3abceea285394

@destinydriven
Copy link
Contributor

@tigrang Awesome thanks, that worked great for me. Perhaps we can add this to the wiki. I'm sure it's a much requested feature.

@tigrang
Copy link
Owner

tigrang commented Apr 6, 2016

@destinydriven is containable actually making a join or is it doing a separate query? Can you check sql log?

@destinydriven
Copy link
Contributor

@tigrang It's doing a left join.

@tigrang
Copy link
Owner

tigrang commented Apr 6, 2016

@destinydriven can you hop on irc?

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

No branches or pull requests

3 participants