-
Notifications
You must be signed in to change notification settings - Fork 753
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
Column that contains dates in relative format is not sorted (using sugar.js and parser-date.js) #1402
Comments
Hi @darkred! I think the problem is that sugar.js modifies the prototype and was causing a javascript error. I did the following:
And it started working: // ==UserScript==
// @name ixIRC - make search results sortable
// @include https://www.ixirc.com/?q=*
// @grant none
// @run-at document-idle
// @require https://cdnjs.cloudflare.com/ajax/libs/jquery.tablesorter/2.28.10/js/jquery.tablesorter.min.js
// @require https://cdnjs.cloudflare.com/ajax/libs/datejs/1.0/date.min.js
// ==/UserScript==
(() => {
// jQuery fix for tables lacking a thead / http://aaron.jorb.in/blog/2010/03/jquery-fix-for-tables-lacking-a-thead/
$('#results-table').prepend($('<thead></thead>').append($('#results-table tr:first').remove()));
$.tablesorter.addParser({
id: "datejs",
is: function() {
return false;
},
format: function(s) {
var str = s.replace('hr', 'hour');
var date = Date.parse ? Date.parse(str) : s ? new Date(str) : s;
return date instanceof Date && isFinite(date) ? date.getTime() : s;
},
type: "numeric"
});
// http://stackoverflow.com/a/26343716/3231411
$('#results-table').tablesorter ({
headers: {
7: { sorter:'datejs'},
8: { sorter:'datejs'}
}
});
})(); |
Thanks a lot for replying @Mottie ! Two notes:
|
Sorry for now getting back to you until now... it took me a while to find the problem. Apparently datejs doesn't support "ago" properly, it parses the time oddly.... if I enter Since Datejs does support And you were right about jQuery... I was messing around with it and probably forgot to reload the page. Anyway, here is the updated userscript: // ==UserScript==
// @name ixIRC - make search results sortable
// @include https://www.ixirc.com/?q=*
// @grant none
// @run-at document-idle
// @require http://code.jquery.com/jquery-3.2.1.min.js
// @require https://cdnjs.cloudflare.com/ajax/libs/jquery.tablesorter/2.28.10/js/jquery.tablesorter.min.js
// @require http://www.datejs.com/build/date.js
// ==/UserScript==
(($) => {
// jQuery fix for tables lacking a thead
// http://aaron.jorb.in/blog/2010/03/jquery-fix-for-tables-lacking-a-thead/
$('#results-table')
.prepend($('<thead></thead>')
.append($('#results-table tr:first').remove()));
$.tablesorter.addParser({
id: "datejs",
is: function() {
return false;
},
format: function(s) {
var str = s
.replace('hr', 'hour')
.replace('min', 'minute')
.replace('sec', 'seconds')
.replace('ago', ''),
date = Date.parse ? Date.parse('-' + str) : s ? new Date(str) : s;
return date instanceof Date && isFinite(date) ? date.getTime() : s;
},
type: "numeric"
});
// http://stackoverflow.com/a/26343716/3231411
$('#results-table').tablesorter ({
headers: {
// 7: { sorter:'datejs'},
8: { sorter:'datejs'}
}
});
})(jQuery.noConflict(true)); |
Update: I've noticed in the test form here http://www.datejs.com/ On the other hand SugarJS parses alright these date cases. I noticed that DateJS is no longer maintained since early 2010/ I found that there is a fork of it that it's actively maintained: DateJS Evolved. And MomentJS unfrotunatey doesn't parse dates in relative format.. |
Hehe |
We posted simultaneously 😃 Your solution works great! |
I'm trying to make a userscript (for Greasemonkey 3.11 in FF 53)
to make the table results in e,g,
https://www.ixirc.com/?q=Prey
sortable.The values of the search results in the above link
in columns 7 and 8 (which contain dates in relative format) are like this:
So, following the documentation and this SO reply (by Mottie)
I wrote this script, which recreates a
<thead>
then calls the tablesorter plugin.Unfortunately the columns 7 and 8 are not sorted when you click the header.
(all other columns are sortable alright)
Plus,when you sort by any other column, clicking the 7th or 8th column header a 2nd time it just restores the initial sorting for them.
I'm (almost) certain that it should work alright.
The text was updated successfully, but these errors were encountered: