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

    (@tobiasbg)

    Hi,

    thanks for your post, and sorry for the trouble.

    The problem here is that there’s no sorting algorithm at the moment (in the Extension) that can account for both the comma and the € symbol.

    Therefore, please try adding one to both of the JS files in the Extension:

    /**
     * Formatted numbers with a comma
     */
    
    "formatted-num-comma-pre": function ( a ) {
    		a = ( a == "-" ) ? 0 : a.replace( /,/, "." );
    		a = a.replace( /[^\d\-\.]/g, "" );
    		return parseFloat( a );
    },
    "formatted-num-comma-asc": function ( a, b ) {
    		return a - b;
    },
    "formatted-num-comma-desc": function ( a, b ) {
    		return b - a;
    },

    Put that right before the lines

    /**
     * Numeric Comma (numbers like 0,5), NOT detected automatically!
     */

    Then, please try this for the “Custom Commands”:

    "aoColumnDefs": [ { "sType": "formatted-num-comma", "aTargets": [ 4 ] } ]

    This should then fix the sorting in the “effektive monatliche Kosten” column.

    Regards,
    Tobias

    Thread Starter jackandthejuice

    (@jackandthejuice)

    Hi,

    thanks for your very fast response. Unfortunately your workaround didn’t fixed the problem. Now sorting isn’t possible anymore as you can see.

    I added the lines above to jquery.datatables.sorting-plugins.js and also changed the custom command but it had no effect.

    Thanks for your help!

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    you’ll also have to add it to the minified version of the file. For now, it’s probably the easiest to simply copy the modified content of the non-minified file into the minified file.

    Regards,
    Tobias

    Thread Starter jackandthejuice

    (@jackandthejuice)

    Hi,

    ok, thanks – not sure about that. I added the code also to the minified js-file but sorting is still impossible. Any further ideas?

    Thanks!

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    just adding it at the end is not enough, it needs to be in the same position. As that’s not easy in the minified file, I meant this:
    Please delete “jquery.datatables.sorting-plugins.min.js”. Then, create a copy of the file “jquery.datatables.sorting-plugins.min.js” and rename it to “jquery.datatables.sorting-plugins.min.js”.

    Regards,
    Tobias

    Thread Starter jackandthejuice

    (@jackandthejuice)

    Hi,

    alright, sorting is working now, but still not in the right way as you can see.

    Thanks!

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    ah, I just saw it now… (I hadn’t taken a look into the HTML source of the page.)
    The problem here is that those cells contain a lot of HTML code, for those small tooltip popups. Those also contain numbers, and as those are not filtered out, they are being taken into account in the sorting, thus giving the wrong results.

    You will therefore need a different approach here (which should then also work for the “monatliche Grundgebühr” column:
    Next to those, you’ll need to add a new column in the table that only gets the numerical value of the cell. For example, on the right of the cell “25,78€” there should then be a cell with the content (and only that) “25.78”.
    We can then hide that extra columns with some more JavaScript code and tell the “real” column to use the data from that column for the sorting.
    After you have added the column, please remove the “Custom Command”

    "aoColumnDefs": [ { "sType": "formatted-num-comma", "aTargets": [ 4 ] } ]

    again, and instead add

    "aoColumnDefs": [ { "iDataSort": 5, "aTargets": [ 4 ] }, { "bVisible": false, "aTargets": [ 5 ] } ]

    That will hide the new column, but the current column will use it for sorting.

    Regards,
    Tobias

    Thread Starter jackandthejuice

    (@jackandthejuice)

    Hi Tobias,

    thanks for your reply. I already supsected the html code in the columns behind this failure. I’ll use the weekend and give your proposal a try – you will hear from me soon. ??

    Thanks a lot for helping and the really great support! Have a nice weekend!

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    alright, sounds good. As you seem to have some knowledge on DataTables already (with the extra filtering code in your site), the DataTables Documentation at https://www.datatables.net/ should also be helpful with the syntax of those “Custom Commands”, as those pretty much are pure DataTables commands.

    Regards,
    Tobias

    Thread Starter jackandthejuice

    (@jackandthejuice)

    Hi Tobias,

    thanks for your solutions. I’ve just tried your way and it works really fine. I will appreciate your help with a donation.

    Best regards!

    Plugin Author Tobias B?thge

    (@tobiasbg)

    Hi,

    no problem, you are very welcome! ?? Good to hear that this helped!

    And thanks for the gift, I really appreciate it! ??

    Best wishes,
    Tobias

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

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘DataTables Sorting not working’ is closed to new replies.