Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery DataTables Plugin : TypeError: e[j] is undefined

I don't understand why DataTables is throwing this error in FF: TypeError: e[j] is undefined

In IE it's reported as : Unable to get property 'aDataSort' of undefined or null reference

Here is the code

HTML

<table id="fp_promotion_history">
<thead>
    <tr>
        <th>AuditID</th>
        <th>Action</th>
        <th>Description</th>
        <th>User Name</th>
        <th>Audit Date</th>
    </tr>
</thead>
<tbody>
    <tmpl_loop name='fp_history'>
        <tr id="AuditID_<tmpl_var name='AuditID'>">
            <td data-AuditID="<tmpl_var name='AuditID'>"><tmpl_var name='AuditID'></td>  
            <td data-Action="<tmpl_var name='Action'>"><tmpl_var name='Action'></td>
            <td data-Audit_Desc="<tmpl_var name='Audit_Desc'>"><tmpl_var name='Audit_Desc'></td>
            <td data-User_Name="<tmpl_var name='User_Name'>"><tmpl_var name='User_Name'></td>               
            <td data-Audit_Date="<tmpl_var name='Audit_Date'>"><tmpl_var name='Audit_Date'></td>
        </tr>
    </tmpl_loop>
</tbody>
</table>

JQuery

        showDialog({content:data,title:'Financial Promotion Audit Trail History (FPID : ' + $('#fp_promotions_table tr.selected').attr('id') + ')'});                                            

        // turn into a datatable
        $('#fp_promotion_history').dataTable({        
                "sDom": 'R<"H"fr>t<"F"ip>',            
                "bJQueryUI": true,
                "sPaginationType": "full_numbers",
                "iDisplayLength": 25,
                "order": [[ 5, "desc" ]]
        });

What I don't understand is I already have a datatable on the page which is working fine.

I make an AJAX call, display the result (a table) with the JQuery UI Dialog, but when I try to turn it into a DataTable , it just errors?

The documentation implies multiple tables is OK : http://legacy.datatables.net/release-datatables/examples/basic_init/multiple_tables.html

So what am I doing wrong?

Thanks, 1DMF

like image 978
1DMF Avatar asked Jul 04 '14 15:07

1DMF


2 Answers

I believe it was due to the order parameter

"order": [[ 5, "desc" ]] 

It would seem the column ordering is ZERO based, which isn't that clear from the docs : https://datatables.net/reference/api/order()

It keeps mentioning Column 1 as [1] not [0].

like image 50
1DMF Avatar answered Oct 22 '22 05:10

1DMF


This is actually a pretty common error that I stumbled across recently. It can be due to a wrong index in the settings, eg:

  • aaSorting
  • order
  • columnDefs.targets
  • columnDefs.orderData etc.

If your columns are n, you can use indexes between 0 and n-1. Using indexes other than these in the settings, can result to this error. Hope it helps.

like image 2
Jannes Botis Avatar answered Oct 22 '22 03:10

Jannes Botis