extracting data from a table cell for sorting

extracting data from a table cell for sorting

diamonddiamond Posts: 3Questions: 0Answers: 0
edited January 2010 in General
Is it possible to extract data from a table cell for sorting? I have problems sorting ?,š,ž characters so i would like to do something like:

textExtraction: function(node) {
// extract data from markup and return it
var s= node.innerHTML;

s = s.replace("?", "CZ");
s = s.replace("?", "CZ");
s = s.replace("?", "DZ");
s = s.replace("Š", "SZ");
s = s.replace("Ž", "ZZ");
s = s.replace("?", "cz");
s = s.replace("?", "cz");
s = s.replace("?", "dz");
s = s.replace("š", "sz");
s = s.replace("ž", "zz");

return s;
}

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    I'm not 100% sure what you mean. Do you mean you want to do sorting which isn't provided by the internal methods DataTables provides (i.e. custom sorting)? DataTables allows for this via the sorting plug-ins:

    http://datatables.net/plug-ins/sorting
    http://datatables.net/development/sorting

    Regards,
    Allan
  • diamonddiamond Posts: 3Questions: 0Answers: 0
    edited January 2010
    I wanted something like this:

    [code]
    "string-asc": function ( a, b )
    {
    var x = a.replace(/?/g, "CZ").toLowerCase();
    x = x.replace(/?/g, "CZ").toLowerCase();
    x = x.replace(/?/g, "DZ").toLowerCase();
    x = x.replace(/Š/g, "SZ").toLowerCase();
    x = x.replace(/Ž/g, "ZZ").toLowerCase();
    x = x.replace(/?/g, "cz").toLowerCase();
    x = x.replace(/?/g, "cz").toLowerCase();
    x = x.replace(/?/g, "dz").toLowerCase();
    x = x.replace(/š/g, "sz").toLowerCase();
    x = x.replace(/ž/g, "zz").toLowerCase();
    var y = b.replace(/?/g, "CZ").toLowerCase();
    y = y.replace(/?/g, "CZ").toLowerCase();
    y = y.replace(/?/g, "DZ").toLowerCase();
    y = y.replace(/Š/g, "SZ").toLowerCase();
    y = y.replace(/Ž/g, "ZZ").toLowerCase();
    y = y.replace(/?/g, "cz").toLowerCase();
    y = y.replace(/?/g, "cz").toLowerCase();
    y = y.replace(/?/g, "dz").toLowerCase();
    y = y.replace(/š/g, "sz").toLowerCase();
    y = y.replace(/ž/g, "zz").toLowerCase();
    return ((x < y) ? -1 : ((x > y) ? 1 : 0));
    },

    "string-desc": function ( a, b )
    {
    var x = a.replace(/?/g, "CZ").toLowerCase();
    x = x.replace(/?/g, "CZ").toLowerCase();
    x = x.replace(/?/g, "DZ").toLowerCase();
    x = x.replace(/Š/g, "SZ").toLowerCase();
    x = x.replace(/Ž/g, "ZZ").toLowerCase();
    x = x.replace(/?/g, "cz").toLowerCase();
    x = x.replace(/?/g, "cz").toLowerCase();
    x = x.replace(/?/g, "dz").toLowerCase();
    x = x.replace(/š/g, "sz").toLowerCase();
    x = x.replace(/ž/g, "zz").toLowerCase();
    var y = b.replace(/?/g, "CZ").toLowerCase();
    y = y.replace(/?/g, "CZ").toLowerCase();
    y = y.replace(/?/g, "DZ").toLowerCase();
    y = y.replace(/Š/g, "SZ").toLowerCase();
    y = y.replace(/Ž/g, "ZZ").toLowerCase();
    y = y.replace(/?/g, "cz").toLowerCase();
    y = y.replace(/?/g, "cz").toLowerCase();
    y = y.replace(/?/g, "dz").toLowerCase();
    y = y.replace(/š/g, "sz").toLowerCase();
    y = y.replace(/ž/g, "zz").toLowerCase();
    return ((x < y) ? 1 : ((x > y) ? -1 : 0));
    },
    [/code]

    Thank you!
    Domen
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Hi Domen,

    Ah I see - have a look at this thread which considers this topic: http://datatables.net/forums/comments.php?DiscussionID=1212

    Regards,
    Allan
This discussion has been closed.