Count number or rows

Count number or rows

silenssilens Posts: 101Questions: 40Answers: 0

Buenas, me gustaría poder contar el registro total de una tabla. Saber si es posible acceder al valor de datatable "info" con el contador total.

He probado esto y otros códigos pero siempre da 0. Creo que se ejecuta antes que la tabla. como puedo acceder al numero total de registros.

var oTable = $('#tblVentas').DataTable();
  
 var info = oTable.page.info();
  
  var count = info.recordsTotal;
  
  alert(count);

Count siempre es 0

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947
    Answer ✓

    The above code should work. However if you are not showing all your code and performing an ajax request within your Datatables init code then yes you are correct that oTable doesn't exist when var info = oTable.page.info(); executes. In this case you would put that code inside the initComplete option.

    Kevin

This discussion has been closed.