Dom sourced table not returning the correct number of elements in the footer

Dom sourced table not returning the correct number of elements in the footer

MaikelMaikel Posts: 75Questions: 18Answers: 1

datatables 1.12.4.

i have a dom sourced table of about 1800 entries with pagination enabled.
In the footer i print the number of entries, this is generated by jquery. Below the table i print the number of rows from the db, this is generated by php).

These 2 numbers are off, i miss about 500 entries in the datatables footer, if i query it with jquery then i get the correct number of rows returned (see screenshot).

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,433Questions: 1Answers: 10,049 Site admin

    datatables 1.12.4.

    No such version I'm afraid. 1.10.16 is the current and latest release.

    Can you link to a test case showing the issue please? If paging is enabled, then yes, the rows which don't need to be shown in the DOM are not and thus won't be counted with a plain jQuery / DOM selector. You need to use page.info() or rows().count().

    Allan

  • MaikelMaikel Posts: 75Questions: 18Answers: 1
    edited December 2017

    sorry its datatables 1.10.13

    i know about the pagination, but even with it disabled i see this..
    Here is a verry simple example that shows the problem:

    http://ddd.yap-vzw.be/dd/index.html

    dom (via jquery) says there are 1910 rows, datatables api says there are 1301 rows.

    also i run 1.10.13 but the example runs with 1.10.16, and both versions have this

  • rduncecbrduncecb Posts: 125Questions: 2Answers: 28

    Your table has multiple <tbody> tags. I believe datatables only handles a single tbody (although I could be wrong).

  • rduncecbrduncecb Posts: 125Questions: 2Answers: 28
    edited December 2017 Answer ✓

    Your selector $("#table_query tbody tr") shows 1910.
    You have 2 tbody's ($("#table_query tbody"))

    $("#table_query tbody:first tr") reports 1301 which matches what DT is seeing.
    $("#table_query tbody:nth(1) tr") reports 609 which is the difference between the DT value and the first jQuery selector value.

    So, yeah, it's the multiple tbody tags. DT only processes <tr>'s in the first <tbody> tag.

This discussion has been closed.