2014-07-01 10 views
16
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'); 
     }); 
    }); 



    }); 

ich folgende Fehlermeldung, wenn ich auf die Schaltfläche Öffnen klicken:Tables .row() ist keine Funktion Server Seite Verarbeitung Reihe Details

TypeError: dtable.rows is not a function

Was mache ich falsch? Ich folgte dem Beispiel auf der offiziellen Seite. Ich kann ein ähnliches Problem nicht finden, also ist es sehr seltsam.

+0

Haben Sie das 'dataTable'-Plugin integriert? – Justinas

+0

Ja, ich habe das Plugin, die Tabelle zeigt in Ordnung das Problem ist, dass Zeile Details nicht funktioniert –

Antwort

38

Ich hatte das gleiche Problem und habe es gerade durch eine Antwort auf Stack-Überlauf gelöst. Verwenden Sie DataTable() anstelle von dataTable(). Die Methode row().child() funktioniert nicht mit dataTable(). So haben Sie:

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

statt

var dtable = $('#table_echipamente').dataTable({}) 
+0

Ich werde überprüfen, beantworten Sie morgen früh, wie ich zur Arbeit komme und Sie wissen lassen ... –

+0

Ja, das ist es. Vielen Dank! –

+0

Hey, ich hatte das gleiche Problem, basierend auf obigen Kommentar, ich habe versucht, 'DataTable' in 'DataTable' zu ändern. Aber es gibt jetzt Fehler - "DataTable.fnDestroy ist keine Funktion" - http://stackoverflow.com/questions/31906217/getting-error-typeerror-datatable-fndestroy-is-not-a-funktion Bitte helfen Sie! – Futuregeek

1

Ich hatte ähnliches Problem. Stellen Sie sicher, dass die Version der Datentabelle 1.10 oder höher ist.