fixing error when sorting on columns with html data #210

Closed
wants to merge 1 commit into
from

Conversation

Projects
None yet
2 participants

Fixing Uncaught TypeError: Cannot call method 'replace' of null when trying to sort a column that contains HTML data.

@AimanZidan AimanZidan Fixing sorting on columns with html data
Fixing Uncaught TypeError: Cannot call method 'replace' of null  when trying to sort a column that contains HTML data.
c40ea8e
Owner

DataTables commented Jul 11, 2013

The type detection function for the html type won't allow null values to be detected as html type:

function ( data )
{
    return typeof data === 'string' && data.indexOf('<') != -1 && data.indexOf('>') != -1 ?
        'html' : null;
}

Are you using sType to override the type detection? If so, then I'd say you want a plug-in which will do what you are looking for. Either way, a like to a test case showing the issue so I canada unit tests if the fix is to be merged in would be good.

var oTable = $('#table-1').dataTable({
        "iDisplayLength": 10,
        "sDom": '<"H"Tfr>t<"F"ip>',
        "aoColumns": [
            { "mDataProp": "money" },
            { "mDataProp": "balance" }
        ],
        "aoColumnDefs": [
        {
            "sClass": "center",
            "aTargets": [0, 1]
        },
        "bProcessing": true,
        "bServerSide": false,
        "sAjaxSource": "history.php",
        "fnServerData": function (sSource, aoData, fnCallback) {
            $.ajax({
                "dataType": 'json',
                "type": "POST",
                "cache": false,
                "url": sSource,
                "data": aoData,
                "success": fnCallback
            });
        }
    });

Ajax result

$json (
|    aaData => Array (2)
|    (
|    |    ['0'] (
|    |    |    DT_RowId =  40
|    |    |    DT_RowClass =  "gradeM"
|    |    |    balance =  "<a href='receipt?id=40' target='_blank'>View the receipt<\/a>"
|    |    |    money =  "$2.98"
|    |    )
|    |    ['1'] (
|    |    |    DT_RowId =  237
|    |    |    DT_RowClass =  "gradeM"
|    |    |    balance =  "$2.48"
|    |    |    money =  "- $0.01"
|    |    )
|    )
)

Clicking on the balance column for sorting triggers the error.

Owner

DataTables commented Jul 12, 2013

Thanks for that. A bit look that need is going through to the sorting function there looking at your data. I'll try to replicate the issue shortly. Just a little concerned that there might be something else going wrong that I haven't seen!

Owner

DataTables commented Dec 8, 2014

Going through a few old issues - sorry for the huge delay! I've not been able to recreate the issue described here with the latest version of DataTables: http://live.datatables.net/lepedohu/1/edit so going to close.

DataTables closed this Dec 8, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment