• Background: I am using the transform shortcode below to sort the table by the AUDIENCE field… which is the number of people who participated in an event. I am using Contact Form DB Version 2.10.29…not able upgrade to the latest version just yet.

    NaturalSortByField(AUDIENCE,DESC) &&AddRowNumberField(#,1)

    Problem: Numbers with 7 digits or greater are not being sorted out of order. I noticed it is the second comma in a number (separating millions from thousands) which causes those numbers to be sorted out of order. If I remove that second comma, the number is sorted correctly, similar to the other numbers.

    Example:
    6,453,324 – sorts out of order
    6453324 or 6453,324 – sorts the number correctly

    Full Shortcode

    [cfdb-table form=”Peanut Allergy” show=”#,RANKING,MARKET,OUTLET,NETWORK,FORMAT,PREVIEW-ONLINE-URL,DATE,TIME-local,LENGTH,AUDIENCE” role=”Anyone” permissionmsg=”false” trans=”NaturalSortByField(AUDIENCE,DESC) &&AddRowNumberField(#,1)” headers=”#=#,RANKING=RANKING,MARKET=MARKET NAME,OUTLET=OUTLET,NETWORK=NETWORK,FORMAT=FORMAT,PREVIEW-ONLINE-URL=TV RADIO PREVIEW-ONLINE URL,DATE=DATE,TIME-local=TIME (local),LENGTH=LENGTH,AUDIENCE=AUDIENCE” id=”mytable” style=”#mytable body,td,th,tr,div { font-size: 12px; }”]

    Any help with this issue would be greatly appreciated. Thanks so much!

    • This topic was modified 7 years, 9 months ago by micha002.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Michael Simpson

    (@msimpson)

    Unrelated: remove the space before && (may cause a problem).

    I looked into this a bit. This get evaluated by the PHP strnatcmp function. Researching this, I see that it does not recognize commas the way we expect, but treats them more like “.”.

    If the information in that field is all numbers, then just use SortByField instead of NaturalSortByField

    Thread Starter micha002

    (@micha002)

    Thanks, Michael. I have to tell you how much I appreciate all of the support and time you put into this. I purchased the editor and will donate to help keep this plugin going.

    The data in that field are all numbers.

    Using SortByField, instead of NaturalSortByField, does a lexical sort instead of a numerical one. Need to have the highest number first and descend from there.

    As a work around, I removed the commas from the larger numbers and it sorts correctly, but the numbers are harder to read without the commas. Please let me know if you have any additional suggestions. Thanks again.

    I also removed the space before && – thanks for catching that.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Contact Form DB] Problem sorting larger numbers’ is closed to new replies.