Autodetection of "html" sType

Autodetection of "html" sType

squigsquig Posts: 14Questions: 0Answers: 0
edited May 2010 in General
Hi all,

as I unterstand the documentation of the sType parameter (http://datatables.net/usage/columns#sType) columns wich contain html should be automatically detected and sorted accordingly, the html should be stripped before sorting.

But when I look at my generated tables (DataTables 1.6.2), all columns which contain html are marked to be sorted as "string".

Am I missing something here?


With kind regards,

squig

Replies

  • allanallan Posts: 63,217Questions: 1Answers: 10,415 Site admin
    Hi squig,

    DataTables doesn't actually auto detect an HTML type - sounds like a very good idea for a plug-in though...

    What you can do is to change the default from 'string' to auto. In 1.6 you need to edit the code for that. In 1.7 you can set the sType for all columns to be 'html' but using aoColumnDefs: http://datatables.net/new/1.7 .

    Type detection for HTML added to the to-do list...

    Regards,
    Allan
  • squigsquig Posts: 14Questions: 0Answers: 0
    Hi Allen,

    so when I use aoColumnDefs to set sType to 'html' will this be the new default value? So is it overriden by a type detection plugin when it detects another type, e.g. 'numeric'?


    With kind regards,

    squig
  • allanallan Posts: 63,217Questions: 1Answers: 10,415 Site admin
    Hi squig,

    You are correct, using aoColumnDefs would override all the other types. I was thinking about an automatic type detection plug-in to deal with this and it's actually very simple, while retaining all of the other type detection options:

    Plug-in: http://datatables.net/plug-ins/type-detection#html
    Example: http://datatables.net/beta/1.7/examples/plug-ins/html_sort.html

    This will work with 1.6 (probably 1.5 as well), but I'll include this example in future releases as I think it's quite useful.

    Regards,
    Allan
  • squigsquig Posts: 14Questions: 0Answers: 0
    edited May 2010
    Hi Allen,

    thank you, now it works like a charme :)

    If you want so see it in action visit: http://www.topicmapsforge.org

    I also write some type detection and sorting plugins for ISO 1355-1 dates which I would like to share:
    [code]
    /*
    * Type detection for dates according to ISO 1355-1 surrounded by HTML.
    */
    jQuery.fn.dataTableExt.aTypes.push(
    function (sData) {
    sData = sData.replace(/<.*?>/g, "");

    if (sData.match(/^(0[1-9]|[12][0-9]|3[01])\.(0[1-9]|1[012])\.(19|20|21)\d\d$/)) {
    return 'date_iso1355_1_html';
    }

    return null;
    }
    );[/code]
    [code]/*
    * Sorting for dates according to ISO 1355-1 surrounded by HTML.
    */
    jQuery.fn.dataTableExt.oSort['date_iso1355_1_html-asc'] = function (a, b) {
    a = a.replace(/<.*?>/g, "");
    b = b.replace(/<.*?>/g, "");

    var isoDateA = a.split('.');
    var isoDateB = b.split('.');

    var x = (isoDateA[2] + isoDateA[1] + isoDateA[0]) * 1;
    var y = (isoDateB[2] + isoDateB[1] + isoDateB[0]) * 1;

    return ((x < y) ? -1 : ((x > y) ? 1 : 0));
    };

    jQuery.fn.dataTableExt.oSort['date_iso1355_1_html-desc'] = function (a, b) {
    a = a.replace(/<.*?>/g, "");
    b = b.replace(/<.*?>/g, "");

    var ukDatea = a.split('.');
    var isoDateB = b.split('.');

    var x = (isoDateA[2] + isoDateA[1] + isoDateA[0]) * 1;
    var y = (isoDateB[2] + isoDateB[1] + isoDateB[0]) * 1;

    return ((x < y) ? 1 : ((x > y) ? -1 : 0));
    };[/code]

    With kind regards,

    squig
This discussion has been closed.