Numerical sorting of IPv4 addresses in the table

Trying to sort tables numericaly, and could not find how to do that. In grafana, table column sorting has 3 possible values changed when clicking column header: no sort, ascending, descending.

When data is strings and is sorted it seems to always use alphabetical order. How can I do to have a numerical sorting of my strings ?

Actually my table displays IP adresses, so I need a numerical sorting that is able to understand IP format (v4).

Do I need to add transformation to do that ?

I am currently using Grafana v7.3.7, will an upgrade to latest version add sorting functionalities ?

Replying to myself after about a year … just to prove this forum is not a support forum. Just a collection of user problems and complaints. If you are lucky, your post will be read by another user that had same problem and was able to solve it by himself.

Hi, depending on your datasource, you could try to strip the dots in the IP address and convert it to a number but I’m not quite sure that’s what you’re after. In newer Grafana versions, there’s a transformation that allows you to extract parts of string via regex to different columns - combine that with a convert field type transformation and you’ll be able to sort by every part of the address. That works if you either don’t care about data representation or you don’t want your users to sort. Aside from that, I’m not sure you’re able to do anything with that.

I wouldn’t recommend that at all - after all, there would be no difference
between:

12.23.34.45
1.223.34.45
122.33.4.45
122.3.34.45
122.33.44.5

I’m sure there are more extreme examples if you choose the digits carefully.

Antony.

Agree with the use of REGEX would be the approach here.

The best way I see here is to make sure that each octet is 3 numerical value (ensure it’s not 1 or 2). This way there the sorting order can be done consistently, e.g. using the above IPs:

Original IP Zero-padded IP
12.23.34.45 012.023.034.045
1.223.34.45 001.223.034.045
122.33.4.45 122.033.004.045
122.3.34.45 122.003.034.045
122.33.44.5 122.033.044.005

Apply sorting afterwards.

Then I guess you can strip the padded 0s on the front-end as another transform / override if you really want it off.