This topic is locked

How to sort IP addresses

3/13/2019 3:00:22 PM
PHPRunner Tips and Tricks
admin

This solution is MySQL specific. It will also work the same way in ASPRunner.NET and ASPRunnerPro.
Question:
I have a list IP addresses in my database. When I look at them in a list view they are not in order because of the format:
10.10.10.1

10.10.10.10

10.10.10.7

10.10.10.8

10.10.10.9
and so on. In my SQL query I can use INET_ATON(address) to change it to a whole number, however I can't get it to work for the list page.
Answer:

  1. Add a calculated field to your SQL query:

select

...

INET_ATON(address) as addressN

...


2. Open the List page in Page Designer and switch your grid to Advanced. Add addressN field to the grid.

Then delete addressN field value element and address field header like on screenshot below.


Then move items and delete extra column to make the grid look nice. So now we displaying address field but sorting data by calculated field addressN. This technique can be applied to many other situations.