Sorting only works in the third execution

Sorting only works in the third execution

redsunsetredsunset Posts: 44Questions: 15Answers: 0
edited June 2019 in Free community support

hi all!
I have some columns with around 15000 rows that have some currency values like "92.02 €". this string is enclosed by html tags. So i tweaked the current currency plugin a little bid to make the sort function working for this data:

//plugin so the sort function even works with currency ---------------------------------------------------------------------------
jQuery.extend( jQuery.fn.dataTableExt.oSort, {
    "currency-pre": function ( a ) {

    a = a.replace(/<\/?[^>]+(>|$)/g, ""); // delete html tags of string
    a = a.replace(/[^\d\-\.]/g, ""); // delete currency or whatsoever

        return parseFloat( a );
    },

    "currency-asc": function ( a, b ) {
        return a - b;
    },

    "currency-desc": function ( a, b ) {
        return b - a;
    }
} ); 

It works great BUT now comes the strange thing:
It only works after I do a Ascending sort, than a descending sort, and THAN in the THIRD sorting attemp (when sorting ascending again) the sorting displays correctly. But I always have to run the sorting twice in this column (the first two runs are missing several rows and so displaying the sorting not correctly) to show the correct sorting of that column by the number value.

How can I fix it, so the sorting would be right after the first attemp to sort this column?

best greetings and thank you in advance!

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    Hi @redsunset ,

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • redsunsetredsunset Posts: 44Questions: 15Answers: 0
    edited June 2019

    sorry I am not able to reconstruct this in an extra table. there is a massive db and a massive data collection inside member area that is not public. What I can do is to give you my login details (via Email), so you can see the page.

    i now have the problem that even in some different sorting actions the result is different. sometimes its correct. sometimes its wrong ... totally strange

    best greetings
    RedSunset

  • redsunsetredsunset Posts: 44Questions: 15Answers: 0

    can be closed! I fixed it ... there were some empty values that needed to be set = 0.00.
    anyway I am sure that this tweak will help someone who also has html and/or a currency or any other symbol in his table and wants to sort it.
    best greetings

This discussion has been closed.