Error thrown when triggering 'draw' event in a datatable in child row (DataTables 1.10)

Error thrown when triggering 'draw' event in a datatable in child row (DataTables 1.10)

RagingTrollRagingTroll Posts: 34Questions: 3Answers: 0
edited January 2014 in General
You can check it here http://jsfiddle.net/E8D9n/6/

[code]//Parent table will attach to 'draw.dt.DT_details' and 'column-visibility.dt.DT_details' events on child.show()
$('#parent').on('draw.dt.DT_details', function(e){
console.log(e);
if(e.namespace != 'DT_details.dt')
alert('namespace: ' + e.namespace + ' is not equal to: DT_details.dt');
});

//Child table will trigger on draw.dt when finished drawing rows
$('#child').trigger('draw.dt');

//test with the correct namespace
$('#child').trigger('draw.dt.DT_details'); //jQuery will create an event with namespace DT_details.dt instead dt.DT_details (jQuery internaly sorts the splitted array, dont know why :S)

//Pseudo code
// var api = $('#parent').DataTable({...});
// api.row(0).child($('', {'id': 'child'}), 'tdclass')
// api.row(0).child.show();
// $('#child').DataTable({...}); //here will be triggered 'draw.dt' event and parent table will catch it ()

//Pasted from dataTable 1.10 source:
/*
table.on('draw' + namespace, function (e) {
table.find('tbody tr').each(function (e) {
if (e.target !== table.get( 0 )) return; //FIX: to ignore draw events from a child table
// Look up the row index for each row and append open row
var rowIdx = _fnNodeToDataIndex(settings, this); //Here rowIdx will be null for the child tr
var row = settings.aoData[rowIdx];

if (row._detailsShow) { //here the exception will be thrown beacuse row will be undefined for the child tr
row._details.insertAfter(this);
}
});
});
*/[/code]

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    I'm being thick and not getting it I'm afraid. Could you explain in a little more detail, perhaps with an example that shows the breakage live? This is a test case showing it working: http://live.datatables.net/ohUd/1/edit

    Allan
  • RagingTrollRagingTroll Posts: 34Questions: 3Answers: 0
    I've put together a test case showing what's not working:
    http://live.datatables.net/IroN/2/edit
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Ah - very interesting. That is being caused by the event bubbling. I'll put a bit of extra protection on it tomorrow when I get into the office.

    Thanks for the test case!

    Allan
  • RagingTrollRagingTroll Posts: 34Questions: 3Answers: 0
    edited January 2014
    Thank you for taking the time to fix it! :)
This discussion has been closed.