Results 1 to 8 of 8

Thread: How to Sort grid with IP addresses

  1. #1

    Default How to Sort grid with IP addresses

    Can any one give an example of sorting a grid which has a column containing an IP address? I found one response to this question but am not sure how to implement it. I have a store pulling data successfully from a MYSQL table but cant figure out how the IP address field can be sorted correctly in my grid panel.

  2. #2

  3. #3

    Default I'm still missing something here

    Animal,

    Thanks for the quick reply, and for all you posts to the forum I've learned quite a bit from your replies. The link you posted does show sorting but my problem is the field I'm trying to sort on contains an IP address and the sort methods referred to in the link don't give me the desired results (unless I'm missing something). My problem is described in the following post.

    http://www.sencha.com/forum/showthre...t+address+grid

    I'm not sure how or where to apply the suggestion made by "micgala" in the reply to the post above. I was hoping to see a more verbose answer of what he was suggesting. Where would I insert the code he has suggested.

  4. #4
    Sencha User Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Nottingham
    Posts
    30,890

    Default

    How do you want to sort them?

  5. #5

    Default

    Ascending, or descending (typically will want them ascending) but in correct numerical order. If you look at the link I posted earlier it describes the problem. The default behavior is to sort the field as a string which prevents the addresses from appearing in a correct order 192.168.1.10 would be placed in an order higher than 192.168.1.2 when sorted ascending. I suppose I could use a php function

    http://php.net/ip2long
    http://php.net/long2ip

    and sort the data for the store before it gets loaded, but if I then sort by another field I can not get back to correct numerical IP order unless I reload the store.

    Ideally if the fix from the earlier link posted reloves this behavior at a grid level that would be what I'm looking for. I just dont know how or where to implement what is suggested in that link. I did PM the "micgala" to see if he could elaborate on the details a bit more but have not seen a reply.

    Thanks again for your assistance.

    Tom C

  6. #6
    Sencha User Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Nottingham
    Posts
    30,890

    Default

    How? What IS correct order for IP addresses?

    All you have to do is implement a sortTypes function which returns comparable values.

  7. #7
    Sencha User Animal's Avatar
    Join Date
    Mar 2007
    Location
    Bédoin/Nottingham
    Posts
    30,890

    Default

    SO mabye

    Code:
    var ipRe = /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/;
    function ip2Long(ip) {
        var b = ip.match(ipRe);
    console.dir(b);
        return (parseInt(b[1], 10) << 24) |
            (parseInt(b[2], 10) << 16) |
            (parseInt(b[3], 10) << 8) |
            parseInt(b[4], 10);
    }

  8. #8

    Default

    Animal,

    I'll give the above a try and see if it can do what I want. I was also thinking there may be a simpler way for me to do this. If I create a new unsigned integer column in my database I can hold a value for the IP which should be easy to sort and achieve the correct result. This new integer field could be hidden in my grid. Can I use the values in this new hidden column as the basis of my sort for the visible column?

Similar Threads

  1. Replies: 19
    Last Post: 21 Jul 2011, 6:18 AM
  2. How to control: sort desc BEFORE sort asc
    By robertlight in forum Ext GWT: Discussion
    Replies: 0
    Last Post: 27 Jun 2010, 5:59 PM
  3. Replies: 0
    Last Post: 26 Feb 2009, 2:09 AM
  4. multiple email addresses validation
    By ext_fan in forum Ext 2.x: Help & Discussion
    Replies: 5
    Last Post: 17 Apr 2008, 10:41 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •