Skip to content

Datepicker range selector filters on the day regardless of settings #512

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

Closed
lindonb opened this issue Feb 23, 2014 · 12 comments
Closed

Datepicker range selector filters on the day regardless of settings #512

lindonb opened this issue Feb 23, 2014 · 12 comments

Comments

@lindonb
Copy link

lindonb commented Feb 23, 2014

With version 2.15.5 the uiDatepicker always filters on the day regardless of settings. I have the following filter_formatter settings:

filter_formatter : {
    1 : function($cell, indx){
         return $.tablesorter.filterFormatter.uiDatepicker($cell, indx, {
             changeMonth: true, 
             changeYear: true
         });
    }
}

The issue seems to be that the input.dateRange element has been set as follows:

<input class="dateRange tablesorter-filter" type="hidden" value="1393131600000 - 1393217999000" placeholder="" data-column="1" data-lastsearchtime="1393186886931"></input>

If I comment out line 751 of jquery.tablesorter.widgets-filter-formatter then at least nothing is filtered, but dates still show in the from and to fields (with the to field showing the raw UNIX timestamp). Here is line 751 that I commented out:

return $input.val( o.from ? ( o.to ? o.from + ' - ' + o.to : '>=' + o.from ) : (o.to ? '<=' + o.to : '') );
@Mottie
Copy link
Owner

Mottie commented Feb 24, 2014

I'm not seeing this issue on my end... maybe just clear out your saved filter searches:

  • Set filters_saveFilters to true
  • Make sure there is a reset button on the page, and add: filter_reset: '.reset'
  • Load the page, then reset the filters. This will clear out the saved search.

Or, at least in Chrome:

  • Open the developer tools.
  • Go to "Resources" > "Local Storage"
  • Find the domain where this issue is popping up (it would be filter:// for the local drive).
  • Click on the "tablesorter-filters" key row and press Delete.

The way the filter formatter works now is that when you hit the reset button, it returns the values back to their default values, not empty strings. For the uiDatepicker, it is set by the from and to options (defaults are empty strings).

@lindonb
Copy link
Author

lindonb commented Feb 25, 2014

Hmmm, that didn't work for me as I get values there even without anything in local storage and with from and to not set. I will keep looking on my side now that I know you're not seeing the issue.
Thanks

@Mottie
Copy link
Owner

Mottie commented Feb 25, 2014

Well, maybe I am not understanding the problem. Do you see the same issue in this demo? It is using the same settings as above.

Are you sure you're using the latest filter widget and filter formatter scripts?

@Mottie Mottie added the Widget label Mar 4, 2014
@lindonb
Copy link
Author

lindonb commented Mar 16, 2014

Hi @Mottie,

I'm still having the same issue and can't figure out what's wrong with the code. I have a demo at http://remote.frela.info in case you are able to take a look (I use a database so I can't demo at jsfiddle).

You can see that it filters upon loading on from and to dates even though I have those set to blank (and the to date is a Unix time stamp with too many zeroes at the end). If you click "Clear Filters" the rows appear.
Thanks,
lindon

@Mottie
Copy link
Owner

Mottie commented Mar 16, 2014

Ok, thanks! I finally see the problem, now to find & fix it ;)

@Mottie Mottie added the Bug label Mar 19, 2014
@lindonb
Copy link
Author

lindonb commented Mar 30, 2014

Hi @Mottie,

I can sort of recreate the problem at http://mottie.github.io/tablesorter/docs/example-widget-filter-formatter-1.html. First add date filters in the from and to fields in the two-input column. Then refresh the page. You should see a funny unix stamp in the to field. This is what I'm seeing, although for me it happens also when the table first initializes.

@Mottie
Copy link
Owner

Mottie commented Mar 31, 2014

Hi @lindonb!

I did spend some time on this problem. I found a solution, but got distracted with modifying the cache to better work with some widgets. I'll include this fix "soon"... look for it when I get v2.16 done.

@lindonb
Copy link
Author

lindonb commented Apr 1, 2014

Thanks @Mottie!

When ajax is used, I think this same issue is causing an ajax call to search on the date fields when the table first initializes even if no defaults have been set.
Regards,
lindonb

On Mar 31, 2014, at 8:02 AM, Rob G [email protected] wrote:

Hi @lindonb!

I did spend some time on this problem. I found a solution, but got distracted with modifying the cache to better work with some widgets. I'll include this fix "soon"... look for it when I get v2.16 done.


Reply to this email directly or view it on GitHub.

@Mottie
Copy link
Owner

Mottie commented Apr 21, 2014

Hey @lindonb!

I think I got this bug squashed, but I'd appreciate it if you would make sure :P Thanks!

@lindonb
Copy link
Author

lindonb commented Apr 26, 2014

Hi @Mottie!

The bug is still there for me - see http://remote.frela.info which has been upgraded to 2.16.1. The table first initializes okay but immediately is filtered with a date range of the current day. Seems like the attempt to put placeholders in for today's date is causing the problem. Personally, I would prefer to not have any date placeholders - may be that would help.

Couple of minor differences in the way it behaves compared to before:

  • Now the "to" date is properly formatted instead of being a unix timestamp
  • Clicking on "Clear filters" no longer fixes the issue. The table initializes correctly but then the filter for today is immediately applied

Thanks for taking a look.
Regards,
lindonb

Mottie added a commit that referenced this issue Apr 26, 2014
Needed for older versions of jQuery UI
@Mottie
Copy link
Owner

Mottie commented Apr 26, 2014

Hey @lindonb!

Try the latest update of the filter-formatter script in the working branch

https://github.com/Mottie/tablesorter/blob/working/js/jquery.tablesorter.widgets-filter-formatter.js

For some reason, the datepicker didn't like the date to be set with an empty string, so I changed then to null. See if that solves your problem - it appears to have for me when I test it on your page.

@lindonb
Copy link
Author

lindonb commented Apr 26, 2014

Hi @Mottie - you nailed it! All is well. Thanks so much for the quick work.
Regards,
lindonb

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