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

Issue with filter widget and UI range / slider #1107

Closed
fab-girard opened this issue Dec 18, 2015 · 10 comments
Closed

Issue with filter widget and UI range / slider #1107

fab-girard opened this issue Dec 18, 2015 · 10 comments

Comments

@fab-girard
Copy link

Hello,
I've tried to upgrade tablesorter from 1.16.5 to 1.19.3 (and now 1.20.0) and a problem occurs with a filter function using a jquery UI slider. Here the jsfiddle:
http://jsfiddle.net/f58479re/1/

Try to use slide, an error will occurs : n.split is not a function
Before, I got "05:00,08:00" in n parameter from filter_functions. Now I get an Integer... 946699200000 Seems to have a problem with "parsed" fields.

Thanks for your support,
Fabien

@fab-girard fab-girard changed the title Issue with filter widget and UI range / slide Issue with filter widget and UI range / slider Dec 18, 2015
@TheSin-
Copy link
Collaborator

TheSin- commented Dec 18, 2015

the problem isn't with TS it's in your JS code

n = n.split(',');     n.split is not a function. (In 'n.split(',')', 'n.split' is undefined)

add

console.log(n); return;

before the first split you'll see that n is a unixtimestamp and not a date/time string like you seem to be expecting.

console.log(n); console.log(new Date(n)); return;

you'll see you can just convert it to a time stamp by simply passing it directly to new Date();

I should have stated the reason. It's because of how textExtraction works on the cells, the parser is seeing it as a date and all date date gets stored internally as a unixtimestamp.

here is a working example for you http://jsfiddle.net/f58479re/2/

@TheSin-
Copy link
Collaborator

TheSin- commented Dec 18, 2015

added more explanation and a working example.

@fab-girard
Copy link
Author

Hello,
thanks I thought it was a regression since retourned values have changed. Strange not to get exact content of the cell like before...
Fab

@TheSin-
Copy link
Collaborator

TheSin- commented Dec 18, 2015

I'm going to look deeper into it on the site there is a proposed change to the function params I wonder it that change has started early, I'll talk to @Mottie about it

Sent from my iPhone

On Dec 18, 2015, at 11:57 AM, Fabien Girard notifications@github.com wrote:

Hello,
thanks I thought it was a regression since retourned values have changed. Strange not to get exact content of the cell like before...
Fab


Reply to this email directly or view it on GitHub.

@Mottie
Copy link
Owner

Mottie commented Dec 18, 2015

The reason you're seeing a change from v1.16.5 is because the time parser now extracts out the time in case you manually set the time parser on a full date column like "12/18/2015 6:30 PM" - it will now only target the "6:30 PM"

So, if you look at the filter_function parameters:

// function variables:
// e = exact text from cell
// n = normalized value returned by the column parser
// f = search filter input value
// i = column index
// $r = jQuery element of current row
// c = table.config
// data = combined filter data
0: function( e, n, f, i, $r ) { ... }

You will see that n is the normalized (or parsed) data, so if the time parser is being detected - I'm not sure why since the times in the example have two times with a comma separator - it will parse and save that time as the number of milliseconds since the epoch.

To get exact table cell content, use e.

I updated your demo, and added a "sorter-text" class to the header cell.... but I'm not sure what the slider is supposed to do. I can slide it all the way across and it doesn't do anything. What were you wanting that range slider to do?

@Mottie
Copy link
Owner

Mottie commented Dec 18, 2015

Ok, I fixed the time detection regex.

@TheSin-
Copy link
Collaborator

TheSin- commented Dec 19, 2015

It needs the filtered class added, and when I checked n and e where the same

Sent from my iPhone

On Dec 18, 2015, at 4:45 PM, Rob G notifications@github.com wrote:

The reason you're seeing a change from v1.16.5 is because the time parser now extracts out the time in case you manually set the time parser on a full date column like "12/18/2015 6:30 PM" - it will now only target the "6:30 PM"

So, if you look at the filter_function parameters:

// function variables:
// e = exact text from cell
// n = normalized value returned by the column parser
// f = search filter input value
// i = column index
// $r = jQuery element of current row
// c = table.config
// data = combined filter data
0: function( e, n, f, i, $r ) { ... }
You will see that n is the normalized (or parsed) data, so if the time parser is being detected - I'm not sure why since the times in the example have two times with a comma separator - it will parse and save that time as the number of milliseconds since the epoch.

To get exact table cell content, use e.

I updated your demo, and added a "sorter-text" class to the header cell.... but I'm not sure what the slider is supposed to do. I can slide it all the way across and it doesn't do anything. What were you wanting that range slider to do?


Reply to this email directly or view it on GitHub.

@fab-girard
Copy link
Author

Hello,
for info the e parameter didn't contain exact value but the same value than n... The 2 parameters contain a timestamp and none the exact text. It was the reason of my issue.

Here my scenario: the column contains hour time slot, for instance 08:00,12:00 and 10:00,14:00. By using the slider, I want to filter all lines which contain for instance 12:00,14:00 (12-14 with the slider). Maybe there is a better way to do it...

Regards,
Fabien

@Mottie
Copy link
Owner

Mottie commented Dec 21, 2015

That is odd, the e should contain the exact text. I will investigate further.

Alternatively, you can use the other parameters like this:

0: function( e, n, f, index, $row ) {
  var txt = $row.children().eq(index).text();
  // process txt & return boolean
}

or if you are using the latest filter widget, a data parameter is also included:

0: function( e, n, f, i, $r, c, data ) {
  var txt = data.$cells.eq(data.index).text();
  // process txt & return boolean
}

I tried updating your demo, but it isn't working... I think it's the comparison logic in the return. I'll attempt to figure it out when I get some time today.

@TheSin-
Copy link
Collaborator

TheSin- commented Dec 21, 2015

I agree my tests showed the parser value for e and n. Hence my comment that maybe the planned changes had already accidentally started, my computer was tied up all weekend so I didn't have a chance to check on it either.

and as you can see in my jsfiddle I kinda did the same as @Mottie, I just didn't use children(), cause @Mottie is better then me ;)

@Mottie Mottie closed this as completed in 4e9905f Jan 11, 2016
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

3 participants