details row not working

details row not working

patopatopatopatopatopato Posts: 4Questions: 1Answers: 0

hi there, im following the tutorial that teaches how to show details row on datatables but the following piece of code is giving me problems:

dt.on( 'draw', function () {
$.each( detailRows, function ( i, id ) {
$('#'+id+' td:first-child').trigger( 'click' );
} );
} );

javascript is thelling me that dt isn;t referenced and am agree with that because a cant see where is declared
the datatable is rendered succesfully but the details row doesnt
sorry for my bad english.

Answers

  • allanallan Posts: 61,740Questions: 1Answers: 10,111 Site admin

    Please link to a test case showing the problem so we can debug it, as required in the forum rules.

    Allan

  • patopatopatopatopatopato Posts: 4Questions: 1Answers: 0

    sorry i found the dt reference already
    it was here:

    $(document).ready(function() {
    var dt = $('#example').DataTable( { /////////////////////////////////<---------------------------sorry
    i spent hours trying to
    whats going on. lol but finally i realized about it.

    javascript shows me another error:
    Uncaught TypeError: undefined is not a function
    when i click on the details column

    on the following code:

    $('#example tbody').on( 'click', 'tr td:first-child', function () {
    var tr = $(this).parents('tr');
    var row = dt.row( tr ); ///////////////////////////////// <------------- this line throws me the error
    var idx = $.inArray( tr.attr('id'), detailRows );

        if ( row.child.isShown() ) {
            tr.removeClass( 'details' );
            row.child.hide();
    
            // Remove from the 'open' array
            detailRows.splice( idx, 1 );
        }
        else {
            tr.addClass( 'details' );
            row.child( format( row.data() ) ).show();
    
            // Add to the 'open' array
            if ( idx === -1 ) {
                detailRows.push( tr.attr('id') );
            }
        }
    } );
    

    thanks for your time datatables plugin rocks

  • NewHireNewHire Posts: 2Questions: 0Answers: 0
    edited June 2014

    I am having the same error on line var row = dt.row(tr);

    JavaScript runtime error: Object doesn't support property or method 'row'

  • NewHireNewHire Posts: 2Questions: 0Answers: 0

    I was able to solve my issue, I was referencing lower case .dataTables in my code, it should have been

    var dt = $('#example').DataTable(

  • allanallan Posts: 61,740Questions: 1Answers: 10,111 Site admin

    Ah - good to hear you found the solution. The second top FAQ covers this one.

    Allan

  • hungnguyenjnhungnguyenjn Posts: 2Questions: 0Answers: 0

    In my Datatable, I used both codes Inline Editting and Detail row. When I changed .dataTable to .DataTable as NewHire's solution, Detail row worked but Inline Editting did not work.

    The error is "Uncaught TypeError: undefined is not a function"

    function editRow (oTable, nRow)
    {
    var aData = oTable.fnGetData(nRow); <------ this line error;
    var jqTds = $('>td', nRow);
    jqTds[0].innerHTML = '<input id="cate_name_upd" type="text" value="'+aData[1]+'">';
    jqTds[1].innerHTML = '<input id="cate_name_upd" type="text" value="'+aData[2]+'">';
    jqTds[2].innerHTML = '<a id="config" class="func config" href="#&id='+aData[0]+'" title="Thiết lập"></a><a id="savUpd" class="func sav" href="#&id='+aData[0]+'" title="Lưu"></a><a id="exit" class="func exit" href="#" title="Không sửa"></a>';
    }

    Please! give me an advice, I have spent 2 days but I can't solve this problem

  • hungnguyenjnhungnguyenjn Posts: 2Questions: 0Answers: 0

    Oh...sorry I have just read The second top FAQ Which Allan suggested above and I added .api() to the line

    var row = oTable.api().row(tr);

    it works. Thanks!

  • fagnervalentefagnervalente Posts: 1Questions: 0Answers: 0

    Nice hungnguyenjn ! I resolved my problem using your sugestion:

    var row = oTable.api().row(tr);

    Tankyou!

  • allanallan Posts: 61,740Questions: 1Answers: 10,111 Site admin

    See also the FAQ I linked to before.

    Allan

This discussion has been closed.