• Resolved caswi

    (@caswi)


    Hello,
    I use “tablepress 0.9-RC” and “DataTables Sorting plugins Extension 1.0” but the sorting of European dates fails. Here is my example table:
    Datum,Uhrzeit,Bemerkung
    02.12.2012,14:07,Wert 1
    05.03.2012,07:05,Wert 2
    12.02.2013,12:00,Wert 3
    25.01.2013,22:45,Wert 4

    If I sort column “Datum” the result is
    Datum Uhrzeit Bemerkung
    02.12.2012 14:07 Wert 1
    05.03.2012 07:05 Wert 2
    12.02.2013 12:00 Wert 3
    25.01.2013 22:45 Wert 4

    What’s going wrong?

    https://www.ads-software.com/extend/plugins/tablepress/

Viewing 15 replies - 1 through 15 (of 23 total)
  • Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    thanks for your question, and sorry for the trouble.

    It might be possible that the automatic detection of the European format is not working for some reason. We might therefore need to manually set this format. To do that, please add this to the “Custom Commands” text field in the “Features of the DataTables JavaScript library” section on the “Edit” screen of the table:

    "aoColumnDefs": [ { "sType": "date-eu", "aTargets": [ 0 ] } ]

    The 0 indicates that this shall apply to the first column (counting starts with 0).

    Regards,
    Tobias

    Thread Starter caswi

    (@caswi)

    Hi,

    thanks a lot. This solution works except you have empty cells.

    Regards,
    caswi

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    good to hear that this helps. Can you explain what’s not working with the empty cells?

    Regards,
    Tobias

    Thread Starter caswi

    (@caswi)

    If you insert a row without a date you cannot sort the date column anymore.

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    ah, ok. I see. Yes, it could be possible that the sorting algorithm of the external library does not support empty cells in that case. Sorry about that.
    I hope, that you can still use this.

    Regards,
    Tobias

    I fix it in case you have an ampty cell and/or a non-date or wrong formatted.
    I modified the “date-eu-pre”: function ( date ) as follow:

    "date-eu-pre": function ( date ) {
    		var year = '', // year is optional
    			month, day,
    			character='/';
    		if ( date.indexOf('.') > 0 )
    			character = '.'; // if found, use . as the separator, otherwise use /
    		date = date.replace( " ", "" ).split( character );
    		if ( date.length <= 1 ) {
    			month = '0';
    			day = '0';
    		}
    		else {
    		if ( date[2] )
    			year = date[2];
    		month = date[1];
    		if ( month.length == 1 )
    			month = '0' + month;
    		day = date[0];
    		if ( day.length == 1 )
    			day = '0' + day;
    		}
    		return (year + month + day) * 1;
    	},

    and I added also this just before the ‘return’ to have the not numeric values sorted in some way:

    if ( (year + month + day) * 1 == 0 ) {
    			year = '10000';
    			for (var i = 0; i < date[0].length; i++) {
    				year = date[0].charCodeAt(i) + year;
    			}
    		}
    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    very cool! Sounds like a good solution. Thanks for sharing it!

    Best wishes,
    Tobias

    Hello,

    My sorting of European dates fails too.
    And if i add the custom line, the sorting do not work

    How it’s can be possible?

    (just in case : https://remiloizeau.com/leblog/test/ )

    be sure that the ‘aTargets’ number be correct; it refers to the CURRENT columns dispalyed, in your case should be:

    "aoColumnDefs": [ { "sType": "date-eu", "aTargets": [ 1 ] } ]

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi Rémi,

    before you can use this, you’ll need to install and activate this TablePress Extension: https://tablepress.org/extensions/datatables-sorting-plugins/

    Regards,
    Tobias

    Thank you so much TobiasBg
    (you too faina09).

    It works.

    Have good day.

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    no problem, you are very welcome! ?? Great to hear that this worked!

    Best wishes,
    Tobias

    P.S.: In case you haven’t, please rate TablePress here in the plugin directory. Thanks!

    i have the same problem, the fix didn’t work, as for the “date-eu-pre”: function ( date ) i have no idea where to put it…

    using this
    "aoColumnDefs": [ { "sType": "date-eu", "aTargets": [ 1 ] } ]
    blocks the column from sorting

    any ideas?
    https://alcyone.pl/index.php/kalendarz/

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    thanks for your post, and sorry for the trouble.

    Additionally to adding this to the “Custom Commands” textfield (which you have done correctly), you will need to actually install the sorting algorithms by installing and activating the TablePress Extension from https://tablepress.org/extensions/datatables-sorting-plugins/

    However, this will likely not yet work as expected, as you still have those time values in the cells. You can only have the date value in the cells for the sorting to work.

    Regards,
    Tobias

Viewing 15 replies - 1 through 15 (of 23 total)
  • The topic ‘TablePress sort european dates’ is closed to new replies.