Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

457
Views
Jquery datatable agregar filas

Tengo una tabla de datos en mi página iniciada como a continuación:

 var dataSet = [ { "id": 1, "name": "Bennett Weimann", "email": "jtremblay@example.com" }, { "id": 2, "name": "Bennett Weimann", "email": "buckridge.orin@example.com" } ]; $(document).ready(function () { $('#example').DataTable({ data: dataSet, columns: [ { data: 'id', title: 'Id' }, { data: 'name', title: 'Name' }, { data: 'email', title: 'Email' }, ], }); });

Además, tengo un botón que hace una solicitud de publicación de ajax, en la respuesta obtengo un json

 [{"id":1,"name":"Bennett Weimann","email":"jtremblay@example.com"}, {"id":2,"name":"Bennett Weimann","email":"buckridge.orin@example.com"}]

Si trato de agregar la respuesta como a continuación, aparece un error

 request.done(function (response, textStatus, jqXHR) { table = $('#example').DataTable(); table.clear(); table.rows.add(response); table.draw(); });

El error es "Advertencia de DataTables: ID de tabla = ejemplo - 'ID' de parámetro desconocido solicitado para la fila 0, columna 0. Para obtener más información sobre este error, consulte http://datatables.net/tn/4"

Sin embargo, si copio y pego la respuesta manualmente, no hay ningún problema.

 request.done(function (response, textStatus, jqXHR) { table = $('#example').DataTable(); table.clear(); table.rows.add([ {"id":1,"name":"Bennett Weimann","email":"jtremblay@example.com"}, {"id":2,"name":"Bennett Weimann","email":"buckridge.orin@example.com"} ]); table.draw(); });

Cualquier ayuda apreció lo que podría causar tal error.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Debo haber estado cansado ... después de dormir pude ver que estaba pasando un objeto en lugar de una matriz. Estoy usando php como backend, si creo una matriz como

 $data = array([ "id" => 1, "name" => "foo", "email" => "bar" ]); return $data;

y pasando la respuesta funciona a las mil maravillas

 request.done(function(response, textStatus, jqXHR) { table = $('#example').DataTable(); table.clear(); table.rows.add(response); table.draw(); });
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!