jquery.datatable.js : Uncaught TypeError: Cannot read property 'replace' of null

jquery.datatable.js : Uncaught TypeError: Cannot read property 'replace' of null

erwin16erwin16 Posts: 14Questions: 5Answers: 1

using DataTables, I can see this error in the console, even if my table is correctly displayed ... I guess it's not so important but could it have any collateral effect late ?

the error in the console is :

## assets =>  DataTable-1.10.9/js/jQuery.dataTables.js
Uncaught TypeError: Cannot read property 'replace' of null

and the faulty line is : var sTitle = col.sTitle.replace( /<.*?>/g, "" )

    ####   DataTable-1.10.9/js/jQuery.dataTables.js
    function _fnSortAria ( settings )
    {
       var label;
       var nextSort;
       var columns = settings.aoColumns;
       .../...

       // ARIA attributes - need to loop all columns, to update all (removing old
       // attributes as needed)
       for ( var i=0, iLen=columns.length ; i<iLen ; i++ )
       {
           var col = columns[i];
           var asSorting = col.asSorting;
           var sTitle = col.sTitle.replace( /<.*?>/g, "" );
           var th = col.nTh;
       ../...

Checking it, col.sTitle is null... no default settings

The DataTables.net documentation ( https://datatables.net/reference/option/columns.title ) indicates 2 ways of setting the column titles : I am using the columns() way, and all my titles are correctly displayed ... It doesn't indicates WHEN we should use one way or the other way ...

$('#example').dataTable( {
  "columnDefs": [
    { "title": "My column title", "targets": 0 }
  ]
} );


$('#example').dataTable( {
  "columns": [
    { "title": "My column title" },
    null,
    null,
    null,
    null
  ]
} );

I "guess" it's related to the fact I am using the DataTable API rather than the jQuery dataTable selector ...

# here is my table initialisation 

  // Let datatables render it now - accessing API
  var table = $('#sheet').DataTable({
      dom: "<'row'<'col-xs-6'><'col-xs-6'f>r>t<'row'<'col-xs-6'l><'col-xs-6'p>>", 
      language: { url: langUrl },
      ordering: true,
      searching: true,
      paging: true,
      info: false,
      select: true,
      data: sheet.data,
      columns: column_titles
      columnDefs: [{"targets": [ 0 ],"visible": false}]
  });

This question has an accepted answers - jump to answer

Answers

  • erwin16erwin16 Posts: 14Questions: 5Answers: 1
    Answer ✓

    it's a script loading order; disappear when ordering the scripts loading...

  • allanallan Posts: 54,738Questions: 1Answers: 8,564 Site admin

    Hi,

    Thanks for posting back - good to hear you've got this sorted out :-)

    Allan

This discussion has been closed.