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

table is not sorted by date #47

Open
AndyIggi opened this issue May 25, 2023 · 12 comments
Open

table is not sorted by date #47

AndyIggi opened this issue May 25, 2023 · 12 comments

Comments

@AndyIggi
Copy link

Hello,

we have a medium sized table (8 colums, 44 rows). In the column 7 are different dates inserted in format dd.mm.yyyy
The syntax <sortable7 7=date> is inserted .
Problem: I have tested and found out that, as soon as the table is bigger then 3 rows the sortable function by date is not working anymore.
sortable_bug

Could you check/help me in this case?

@FyiurAmron
Copy link
Owner

@AndyIggi can you provide a complete snippet that reproduces this? It would speed things for me.

@FyiurAmron FyiurAmron changed the title table don´t sort by date table is not sorted by date May 26, 2023
@AndyIggi
Copy link
Author

Hi,

you mean this?
sortable bug 2

@FyiurAmron
Copy link
Owner

FyiurAmron commented May 26, 2023

@AndyIggi yes, but as a code block from the table-generating text only, not a pasted image :D

@AndyIggi
Copy link
Author

AndyIggi commented May 26, 2023

<sortable8 8=date>

^Col1^Col2^Col3^Col4^Col5^Col6^Col7^Col8^Col9|
|test1|xyz| | | | | |22.01.2022| |
|Test2|abc| | | | | |19.01.2023| |
|Test3|def| | | | | |24.01.2024| |
|Test4|ghi| | | | | |13.02.2021| |

</sortable>

@AndyIggi
Copy link
Author

Hi FyiurAmron, do you have any news regarding the Problem?

@FyiurAmron
Copy link
Owner

@AndyIggi sorry, I'm basically swamped with work ATM. I'll do take a look at it as soon as I'm able to, though, probably in the couple of coming weeks. Any debugging help is welcome, though.

@Chris75forumname
Copy link

Chris75forumname commented Jul 12, 2023

@AndyIggi
Hi, I ran into the same problem today. This is just a hack for the date format dd.mm.yyyy !
Just replace the sort_date function in /dokuwiki/lib/plugins/sortablejs/script.js, like so:

    sort_date: function ( a, b ) {
        var a_arr = a[0].split('.');
        var a_ami = a_arr[1] + '/' + a_arr[0] + '/' + a_arr[2];

        var b_arr = b[0].split('.');
        var b_ami = b_arr[1] + '/' + b_arr[0] + '/' + b_arr[2];

        var aa = new Date( a_ami ); 
        var bb = new Date( b_ami );

    //  var aa = new Date( a[0] ); 
    //  var bb = new Date( b[0] );

        return ( aa > bb ) - ( aa < bb );
    },

Tested and works with the following table syntax:

<sortable 1=nosort 2=nosort 3=date>
^Col1^Col2^Col3^
|Test1|xyz|22.01.2022|
|Test2|ghi|08.02.2021|
|Test3|def|24.01.2024|
|Test4|xyz|22.07.2025|
|Test5|ghi|13.02.2021|
|Test6|def|24.01.2024|
|Test7|xyz|22.04.2020|
|Test8|ghi|13.08.2021|
|Test9|def|24.12.2024|
</sortable>

Date format yyyy-mm-dd can coexist in this scenario, but would have to be labeled as 3=alpha in order for it to work.

Cheers!

@Chris75forumname
Copy link

Chris75forumname commented Jul 12, 2023

@FyiurAmron
No action needed, afterall! Everything works alright. I updated the documentation to reflect the code in the sort_date function, which sorts dates with US american date format mm/dd/yyyy and yyyy-mm-dd, of course.
Cheers!

@FyiurAmron
Copy link
Owner

FyiurAmron commented Jul 12, 2023

@Chris75forumname well, you're not wrong, but you're not right. The current sorting is done via new Date() c-tor, which, in theory, should work like this: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#date_time_string_format ; tl;dr ISO format has to be supported, and

Non-standard strings can be parsed in any way as desired by the implementation

in practice, it usually accepts legacy formats (based on browser etc.), such as:

  • MM-dd-yyyy
  • yyyy/MM/dd
  • MM/dd/yyyy
  • MMMM dd, yyyy
  • MMM dd, yyyy

IMVHO this should be still fixed here in the plugin to allow passing the formatting string for dates and to use locale-based default format for this, but the exact implementation of the fix is TBD.

@Chris75forumname
Copy link

@FyiurAmron
Thank you very much for your reply and more information! I updated the plugin homepage accordingly. I think this will help alot!
Cheers!

@LMS235
Copy link

LMS235 commented Nov 6, 2023

We have now also implemented the "workaround", so it now also works with DD.MM.YYYY. Can the plugin generally be extended to use the EU spelling (DD.MM.YYYY)?

@FyiurAmron
Copy link
Owner

FyiurAmron commented Nov 6, 2023

@LMS235 yes, and it shouldn't be too difficult to support _some) attempts to guess the most obvious formats TBH (via a regex e.g.), but the key issues are twofold: 1. my time limits (I'm basically devoid of any free time to spend on OSS pet projects now), 2. my strong preference to do a proper solution, which basically isn't possible without an external library or some kludges, see tc39/ecma402#342 (comment) etc. for the discussion.

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

4 participants