Question about type detection

Question about type detection

HarfordHarford Posts: 6Questions: 0Answers: 0
edited July 2009 in Plug-ins
Hello,

I know there is not ip address sorting function in the DateTables.Then I want to sort ip address as string type. So I write the code as below:

jQuery.fn.dataTableExt.aTypes.push(
function ( sData )
{
var re=/\d+\.\d+\.\d+\.\d+/;
if(re.test(sData))
return "string";
return null;
}
);

But it does not work. The ip address column still can not be sorted at all.
Could please help me with this? I only want the ip address to be sorted as string type.

Thank you very much!

Replies

  • allanallan Posts: 54,909Questions: 1Answers: 8,606 Site admin
    Hi Harford,

    I think you have started along the right track, but not quite there yet! From the code you have added, you don't actually have any IP address sorting. What you have added is detecting an IP address as a string - which DataTables would do anyway!

    What you need to do is detect an IP address type, and then add the sorting functions required for that IP address. You can see an example of how you might add sorting and type detections functions here: http://datatables.net/examples/example_sorting_plugin.html

    There are also a number of examples on the plug-ins page: http://datatables.net/plug-ins

    Regards,
    Allan
  • HarfordHarford Posts: 6Questions: 0Answers: 0
    Thanks for your advise.

    I do not think you understand me clearly. I do want the ip address to be detected as string.

    As you say, the ip address is always detected as string by DataTables. But when I click on the ip address column, the column can not be sorted, which you can test to see it.

    I already have done some other tests. If I set the ip address column's(the 2nd column) as below:
    "aoColumns": [null,{ "sType": "string" },null,null,null]

    Then the ip address column can be sorted as string successfully. But if I did not set the sType value, then the ip address column can not be sorted.

    Please tell me why this happened? Is this a bug?

    Thank you very much!
  • allanallan Posts: 54,909Questions: 1Answers: 8,606 Site admin
    Hi Harford,

    Got it - thanks for clarifying! Are you using DataTables 1.4.3 (or before)? There was a bug which was fixed around about 1.5 beta 5 (ish) which meant that an IP address was actually (incorrectly) detected as a number. Upgrading to 1.5 beta 9 should fix this for you.

    Allan
  • HarfordHarford Posts: 6Questions: 0Answers: 0
    Yes, I'm using 1.4.3.

    Thank you so much! I'll try 1.5 beta 9.

    Thanks again!
This discussion has been closed.