I have added date filter to the table. Now I want to count the number of rows in the table.

I have added date filter to the table. Now I want to count the number of rows in the table.

shekhardshekhard Posts: 19Questions: 5Answers: 0

Answers

  • kthorngrenkthorngren Posts: 21,342Questions: 26Answers: 4,954
    edited June 2020

    I think you are asking about the recordsDisplay property of the page.info() API.

    Kevin

  • shekhardshekhard Posts: 19Questions: 5Answers: 0

    table.rows().every(function(){
    }) loops through all rows. But I want it to loop through only the rows in the table after the filter is applied.

  • shekhardshekhard Posts: 19Questions: 5Answers: 0

    Can I add the count value to table.rows() so that it only loops through that many rows not all rows

  • kthorngrenkthorngren Posts: 21,342Questions: 26Answers: 4,954

    The rows() API documents how to control the rows that are looped through. The selector-modifier of {search:'applied'} is what you are looking for.

    Kevin

  • shekhardshekhard Posts: 19Questions: 5Answers: 0

    Can you give me a working example

    Like here

      var count = 8;
      table.rows().every(function () {
        console.log(this.data);
    });
    

    I want to print only the first 8 rows. How will I do that.

  • shekhardshekhard Posts: 19Questions: 5Answers: 0
    edited June 2020

    Got the answer

    table.rows({page:'current'}).every(function () {
    console.log(this.data);
    }

    Your answer was correct. Had to use a selector modifier.

  • kthorngrenkthorngren Posts: 21,342Questions: 26Answers: 4,954

    You probably wouldn't be able to use rows().every() for this particular case. Use a for loop and in the for loop use row() , singular, to get the row. The row-selector documents the options for selecting the particular row. However simply passing the for loop variable might not be enough. You may need to use the jQuery selector of :eq().

    The specific answer for your case depends on your table data and what specifically you need. If you want an example for your case please build a simple test case so we can provide a better answer.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

This discussion has been closed.