Skip Navigation

[Resolved] Views isn't sorting numeric fields correctly

This support ticket is created 6 years, 12 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Tagged: 

This topic contains 7 replies, has 2 voices.

Last updated by StanleyT8485 6 years, 11 months ago.

Assisted by: Anton Khalemsky.

Author
Posts
#601875

I am trying to:
Sort numeric fields correctly.

Views is sorting based on the front digit. All the fields with "9" in front are considered the largest with the largest. However, in my data, there are fields which are at least 10x larger.

For example, in the fourth column, Views is seeing 964,870 as the biggest number but in my data, 50,779,054 should be the biggest.

Here is the test page - hidden link

Stan

#601954

Hi Stan,

Thanks for contacting Toolset support.
In order to assist you with that the sorting issue, I'll need to know what kind of field type you are using? Is it Numeric Field or Text Field. Also, is the Field is created using Types or not.

#601959

Hi Anton,
Yes, it is a numeric field by Types.

#601963

I'll need to request temporary access (WP-Admin and FTP) to your site
– preferably to a test site where the problem has been replicated if possible –
in order to be of better help and check if some configurations might need to be changed

Your next answer will be private which means only you and I have access to it.

❌ Please backup your database and website ❌

✙ I would additionally need your permission to de-activate and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important.

#602138

Hi Stan,

I debugged your issue, and I found that issue comes from the comma in the custom field value. Because of the comma it works as string and not as number. Therefore you should remove all commas from the custom field value.

#602220

Those with , should be a number too. I have two questions:
1. How can we make this to be a number?
2. I can remove the commas from the numeric custom fields but how can I add comma via CSS or JS so it still shows the comma but doesn't effect the custom field?

#602413

Hi Stan,
1. How can we make this to be a number?
⇒ You are already using number field and as we said in order to make this field working in order by clause as number field you simply need to remove the comma from your field value (which you already did).

2. I can remove the commas from the numeric custom fields but how can I add comma via CSS or JS so it still shows the comma but doesn't effect the custom field?
⇒ For such customization, you need to build custom shortcode to display your number field in your desired number format.

Here is the reference ticket link that may help you: https://toolset.com/forums/topic/allowing-number-format/#post-374263

#602799

Solved via custom code.