Closed (fixed)
Project:
Views (for Drupal 7)
Version:
6.x-2.5
Component:
page displays
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
11 Jan 2010 at 15:48 UTC
Updated:
7 Sep 2010 at 13:02 UTC
Hi,
I'm trying to sort ip adresses which are entered in a text type field. The current outcome is this:
192.168.164.123
192.168.164.124
192.168.164.4
192.168.164.5
192.168.165.100
192.168.165.20
And I'd like to have it like this:
192.168.164.4
192.168.164.5
192.168.164.123
192.168.164.124
192.168.165.20
192.168.165.100
Is there a way to archieve this or do I have to change the field type?
Thanks in advance!
Nda
Comments
Comment #1
dawehnerSure, write your own sort handler and use INET_ATON(field). This behaves exact like you want it.
Comment #2
Nda commentedAllright thanks dereine. I've been reading up abit on how to do such a thing and it looks like I need to create a module, name it "views_sort_ip" for example, create a .module file and a views_sort_ip_handler_field_something.inc. Then copy some code here and there. Only thing I can't seem to find is where or when I can see if what I'm doing is working yet but I'll try and see what happens.
I've never done anything remotely similar in Drupal yet so if you have some pointers or an example that'd be greatly appreciated.
Thanks!
Comment #3
Nda commentedAllright, I've come this far:
file: views_sort_ip.module
file: views_sort_ip.module
file: views_handler_sort_ip.inc
Now I don't know how to insert the INET_ATON option into the query. I've seen a few examples but all seemed too complicated for what I need and didn't give me an impression on how to get there.
The ip address is in the default node title field so in mysql it would be: "order by INET_ATON(title);" Besides this, I don't know what will happen when I activate the module. Will I get a new option next to sorting ascending or descending or will the field automatically be sorted this way?
Hope you can help.
Kind regards, Nda
Comment #5
kenorb commented