Include the record count in the Pagaination selector (row /page control)

Include the record count in the Pagaination selector (row /page control)

justStevejustSteve Posts: 49Questions: 8Answers: 1

Out of the box the table header includes a caption that displays 'showing x of y'. and another caption mixed with dropdown as:

Show [dropdown for records per page] entries.

I'm sure someone's already merged these two captions down to:

Show [dropdown for records per page] of y entries.

and also sure there was some amount of pain on the way. Either pain or mastery of the API?

This question has an accepted answers - jump to answer

Answers

  • jLinuxjLinux Posts: 981Questions: 73Answers: 75
    edited November 2015

    The only thing I can really thing of, uses the language.lengthMenu setting and provides the row count by just using a standard CSS selector on the table rows

    $(document).ready( function () {  
      var table = $('#example').DataTable({
      "language": {
        "lengthMenu": "Display _MENU_ records of " + $('#example > tbody > tr').length
      }
    });
    } );
    

    Example

    I cant think of a way to get the number of rows in the table from the DT API, as the DT instance hasnt been initiated yet, and the language.lengthMenu doesn't take a closure as a value (so you cant do something fancy like use the API within the closure). So the method I showed is the only way I know, but its possible that im wrong

  • justStevejustSteve Posts: 49Questions: 8Answers: 1

    Thanks much -- and in implementing I realize I hadn't accounted for display of the page offset. It looks as though something can be gained by page().info() but not sure if values would be populated at that point. Should I be looking to jquery to just re-write the contents of the ordersTable_length div after the grid is rendered?

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    Hi,

    I'm sure someone probably has done this, but I'm not aware of any published code for it. A custom feature plug-in would probably be the best way to do it.

    Should I be looking to jquery to just re-write the contents [...]

    That would certainly be another option.

    Allan

This discussion has been closed.