Sorting a Text field that contains only numbers

Moderator: crythias

Post Reply
lperoni
Znuny newbie
Posts: 11
Joined: 07 Mar 2017, 15:11
Znuny Version: OTRS5
Real Name: Lorenzo Peroni
Company: Cassini Consulting

Sorting a Text field that contains only numbers

Post by lperoni »

I have a Dynamic Field of type Text where only numbers are entered (RegEx ^[1-9][0-9]*$).

When I use this DF as a sortable column in e.g. AgentTicketQueue, the sorting works alphanumerically (1, 10, 11, ..., 2, 3, ...) instead of numerically (1, 2, 3, ..., 10, 11, ...) as intended.

How can I fix this? AFAIK, there is no DF type "number".
lperoni
Znuny newbie
Posts: 11
Joined: 07 Mar 2017, 15:11
Znuny Version: OTRS5
Real Name: Lorenzo Peroni
Company: Cassini Consulting

Re: Sorting a Text field that contains only numbers

Post by lperoni »

Until OTRS (or KIX) implement dynamic fields of type integer, I'll have to solve this with padding, i.e. 0001, 0002, 0003, ..., 0010, 0011, ...). Unattractive, but manageable.
root
Administrator
Posts: 3960
Joined: 18 Dec 2007, 12:23
Znuny Version: Znuny and Znuny LTS
Real Name: Roy Kaldung
Company: Znuny
Contact:

Re: Sorting a Text field that contains only numbers

Post by root »

You can add custom Javascript, here's a JS example: http://jsfiddle.net/bysz2gkz/

The JS file can be added via the module registrations or global.
Znuny and Znuny LTS running on CentOS / RHEL / Debian / SLES / MySQL / PostgreSQL / Oracle / OpenLDAP / Active Directory / SSO

Use a test system - always.

Do you need professional services? Check out https://www.znuny.com/

Do you want to contribute or want to know where it goes ?
lperoni
Znuny newbie
Posts: 11
Joined: 07 Mar 2017, 15:11
Znuny Version: OTRS5
Real Name: Lorenzo Peroni
Company: Cassini Consulting

Re: Sorting a Text field that contains only numbers

Post by lperoni »

I've tried to run the JSFiddle, but I cannot see it doing anything. How does it sort?
reneeb
Znuny guru
Posts: 5018
Joined: 13 Mar 2011, 09:54
Znuny Version: 6.0.x
Real Name: Renée Bäcker
Company: Perl-Services.de
Contact:

Re: Sorting a Text field that contains only numbers

Post by reneeb »

Perl / Znuny development: http://perl-services.de
Free Znuny add ons from the community: http://opar.perl-services.de
Commercial add ons: http://feature-addons.de
lperoni
Znuny newbie
Posts: 11
Joined: 07 Mar 2017, 15:11
Znuny Version: OTRS5
Real Name: Lorenzo Peroni
Company: Cassini Consulting

Re: Sorting a Text field that contains only numbers

Post by lperoni »

Yes, brilliant, it works like a charm! Thank you very much!

One remark: the RegEx \A[+-]?[0-9]+\z means I may enter e.g. "+7", but this value is not saved. Entering "7" is saved, of course; so is e.g. "-3". I think I'll change the RegEx to \A-?[0-9]+\z in both subs that use it.
Post Reply