Currency columns not sorting properly
-
I’ve imported a .csv file into Tablepress that includes two columns with currency values. When testing the sort function, the columns do not properly sort in terms of highest to lowest dollar value and vice versa. In one, the values go down from under $1 million, then once it reaches the lowest value, starts again at the highest value (in this case over $2 million), and goes down to the lowest value over $1 million. I can’t even figure out the rhyme or reason in how the other column sorts. Thanks so much for any help you can give.
The page I need help with: [log in to see the link]
-
Hi,
thanks for your post, and sorry for the trouble.
Can you please post a link to the page with the table where this problem happens, so that I can take a direct look (the link that you posted only goes to the “Edit” screen which I can’t access)? Thanks!
Regards,
TobiasHi, thank you so much for your response and sorry for the incorrect link. Try this:
https://www.aspenjournalism.org/2018/12/17/draft-housing-table-2/
and enter the password “sorthelp” to access. I hope that works, I wasn’t sure how best to give you access without publishing publicly. Thank you!Hi,
thanks! Now I can see the table. From what I can see, the “Purchase Price” column is working fine. The problem in the “Current value” column is the use of text strings, like “Market Value”. This turns the sorting for that column from number/currency sorting to text/string sorting. Can you replace all those text by a number or currency or maybe leave them empty?
Regards,
TobiasThank you so much! But, there’s still a problem. It worked to remove the text from the “Current Value” column, which is now sorting properly in both directions. However, in the “Purchase Price” column, there are a handful of entries, about 20, which do not sort in the right order. They end up at the bottom of the list regardless of whether the sort is done lowest to highest or highest to lowest. These sort properly in Excel, and I cannot see any difference in how the cells are formatted.
Thank you again!
CatherineHi Catherine,
indeed. The reason for that seems to be a a single space character after those values from that column. This is again turning the sorting into string-based sorting 🙁
The quickest way to remove all those might to export the table to a CSV file and then open that in a text editor. There, you could do a search/replace for ” ;” and replace with just “;”. Then, re-import the CSV file into TablePress.Regards,
TobiasSorry to continue this drama, but when I look at the CSV file in a text editor, I am finding a single space character after ALL the currency values, in both column, not just that handful of values that is not sorting properly … (I could send you a screen shot of it but cannot figure out how to attach file.)
Hi,
ah, ok. Then my idea was a bit too quick.
Let’s maybe try explicitly setting a data type. For that, please add this to the “Custom Commands” text field on the table’s “Edit” screen:"columnDefs": [ { "type": "formatted-num", "targets": [ 3, 6 ] } ]Regards,
TobiasI’m sorry, but do you mean in the Tablepress plug-in or in the Excel spreadsheet? Or elsewhere? Because I’m having a hard time finding the “Custom Commands” function anywhere. Thanks.
Hi,
this is on the table’s “Edit” screen in TablePress – but you will have to be logged-in as an Administrator on a WordPress single-site installtion or as a Superadmin on a WordPress multisite installation.
Regards,
TobiasOK, I’ve figured out where to enter that code into the Custom Commands field. Now, the “table content” is no longer visible when I go into the Tablepress page. And if I look at the actual post, there is no sort function available? And the current value and purchase price fields are now both completely out of order …
Hi,
can you please try copying the code directly from the post above (and not maybe from the email notification)? It seems like there are some extra characters in your code now, and it’s duplicated a few times?
And just to be sure: Where are you no longer seeing the table content? On the table’s “Edit” screen? Most likely the section is just minimized. To show it again, please click on the wide “Table Content” bar that should be on the page.
Regards,
TobiasHello,
OK, I have copied the code directly into the Custom Commands field — it should be correct now. And I am able to view the “Table Content” on that same page. The Purchase Price field is still not sorting properly there. And if I preview the Post (through WordPress) using the password-protected link I gave you, the sort function is not available on any of the columns.Thank you for your patience on this.
CatherineHi Catherine,
did you copy the “Custom Command” directly from my post above? It should be consisting of several actual quotation marks around some words, but NOT the word “quot” between an ampersand and a semicolon.
Regards,
TobiasI did — I copied and pasted directly from your post. I’m not sure what happened that the text of the Custom Command changed, but now I just did it again, and the sort option is once again available. BUT, we still have the same issue: in the Purchase Price column, the same 20 or so records are showing up at the bottom, out of order.
Thank you,
CatherineHi Catherine,
that’s weird. Everything in the code looks good to me. If possible, I’d like to take a direct look at this on your site. Could you therefore please get in touch via email (the address is in the main plugin file “tablepress.php”)?
Regards,
Tobias
The topic ‘Currency columns not sorting properly’ is closed to new replies.