Counting number of entries on datatable

Counting number of entries on datatable

zemetalzemetal Posts: 5Questions: 1Answers: 0

Hi all,

I got to this thread:

http://datatables.net/forums/discussion/2278/how-to-get-number-of-rows

The problem is that the javascript stops when I run the answers pointed in that thread ( oTable.fnSettings().fnRecordsTotal() and oTable.fnGetData().length ).

I made an example using a previous made one, where I added a button that works when I comment the function meant to count the number of entries, but as soon as I uncomment it, the value doesn't get anything:

http://live.datatables.net/niwajato/41/edit

I think it might be because the thread is 5 years old, and up to now those methods have been deprecated and a new method(s) have been implemented.

Any help would be very appreciated.

José Gonçalves

Replies

  • zemetalzemetal Posts: 5Questions: 1Answers: 0

    Got an alternative working:

    using pageInfo, I can get the attribute recordsTotal to tell me how many records the table has.

    Code:

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

    Working example here: http://live.datatables.net/niwajato/42/edit

  • allanallan Posts: 63,692Questions: 1Answers: 10,500 Site admin

    Yes, page.info() will tell you or data() (table.data().length() for example).

    Allan

  • zemetalzemetal Posts: 5Questions: 1Answers: 0

    Hi Allan,

    Thanks for your reply.

    I think I'll use oTable.data().length instead, since it spends one less resource than the method I've found :)

This discussion has been closed.