Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dataTables .row( ) is not a function servers side processing row details

 function format ( d ) {
return 'Full name: <br>'+
       'Salary:<br>'+
       'The child row can contain any data you wish, including links, images, inner     tables etc.';
  }

 $(function() {
 var dtable = $('#table_echipamente').dataTable( {
    "processing": true,
    "serverSide": true,
    "ajax": {
        "url": "inc/table_echipamente.php",
        "type": "POST"
    },
    "columns": [
        {
            "class":          "details-control",
            "orderable":      false,
            "data":           null,
            "defaultContent": ""
        },
        { "data": "beneficiar" },
        { "data": "distribuit" },
        { "data": "data_distribuit" },
        { "data": "denumire" },
        { "data": "nr_inventar_nou" },
        { "data": "nr_inventar_vechi" },
        { "data": "gestionar" },
        { "data": "observatii" },
        { "data": "optiuni" }
    ],
    "order": [[1, 'asc']]

  });

  // Array to track the ids of the details displayed rows
  var detailRows = [];

  $('#table_echipamente tbody').on( 'click', 'tr td:first-child', function () {
    var tr = $(this).closest('tr');
    var row = dtable.row( tr );
    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') );
        }
    }
   } );

  // On each draw, loop over the `detailRows` array and show any child rows
  dtable.on( 'draw', function () {
    $.each( detailRows, function ( i, id ) {
        $('#'+id+' td:first-child').trigger( 'click' );
      } );
  } );



  } );

i get the following error when i click on the open button:

TypeError: dtable.rows is not a function

What am i doing wrong? i followed the example on the official site. I can't find a similar problem so it is very weird.

like image 881
Razvan.432 Avatar asked Jul 01 '14 12:07

Razvan.432


2 Answers

I had same problem and just got it solved through an answer on stack overflow. Use DataTable() instead of dataTable(). Method row().child() will not work with dataTable(). So you will have:

var dtable = $('#table_echipamente').DataTable( {})

instead of

var dtable = $('#table_echipamente').dataTable( {})
like image 94
Kunbi Avatar answered Oct 20 '22 13:10

Kunbi


I had similar issue. Make sure that the data table version is 1.10 or above

like image 29
Spider man Avatar answered Oct 20 '22 13:10

Spider man