Where can I change "Showing # to # of # entries"?

Where can I change "Showing # to # of # entries"?

Connorln3Connorln3 Posts: 6Questions: 3Answers: 0

It has been a long time since I set up an application using dataTables. I have no idea where I can change the numbers that show up in the "Showing # to # of # entries" below each table. Here is some code examples of my use of dataTables.

Javascript:

    $(document).ready(function() {

    /*---------------------------------------------------All Table------------------------------------------------------------*/ 
      selected = [];
      selectedEmails = [];

       allTable = $('#allTable').DataTable({
          "order": [[ 1, "asc" ]],
          "aLengthMenu": [[10, 25, 50], [10, 25, 50]],
          "processing": true,
          "serverSide": true,
          "ajax": "/parentclub/parentclub/allData",
          "rowCallback": function( row, data ) {
              if ( $.inArray(data.DT_RowId, selected) !== -1 ) {
                  $(row).addClass('selected');
              }
          },

          "columnDefs": [
                {
                    "targets": [ 0 ],
                    "visible": false,
                    "searchable": false,
                },
                { "bSortable": false, "aTargets": [ 3 ] }
            ]

        })

        $('#allTable').dataTable().fnSetFilteringDelay()

        $('#allTable tbody').on('click', 'tr', function() {

          var id = allTable.row(this).data()[0];
          var id2 = allTable.row(this).data()[2];
          var index = $.inArray(id, selected);
          var index2 = $.inArray(id2, selectedEmails);

          if ( index === -1 ) {
              selected.push( id );
              selectedEmails.push( id2 );
          } else {
              selected.splice( index, 1 );
              selectedEmails.splice( index2, 1 );
          }
        //console.log(selected)
        //console.log(selectedEmails)
        //console.log(this)
          $(this).toggleClass('selected');
        } );

        $('#myInput').on( 'keyup', function () {
          table.search( this.value ).draw();
        } );
});

This is where the above is getting the data from via the ajax request (controller action):

def allData() {

    def columnNames = ["id", "lastName", "email", null, "studentEnumber", "renewDate", "cell", "statusInd" ]
    params.offset = params.int('start')
    session.offset = params.int('start')

    session.page = params.int('start') / params.int('length')

    params.max = params.int('length')
    session.max = params.int('length')

    params.sort = columnNames[params.int("order[0][column]")]
    session.sort = params.int("order[0][column]")
    params.order = params["order[0][dir]"]
    if (!["asc", "desc"].contains(params.order)) {
        params.order = "asc"
    }
    session.order= params["order[0][dir]"]
    session.search = params["search[value]"]
    def count, parents

    if(params["search[value]"] == null || params["search[value]"] == "") {

        def criteria = Parent.createCriteria()
        count = Parent.count()
        parents = criteria.list {
            order(params.sort, params.order)
            order('id', params.order)
            maxResults(params.max)
            firstResult(params.offset)
        }

    } else {

        def searchString = "%${params['search[value]']}%"
        def criteria = new DetachedCriteria(Parent).build {
            or {
                ilike('firstName', searchString)
                ilike('lastName', searchString)
                ilike('email', searchString)
                ilike('statusInd', searchString)
                ilike('studentEnumber', searchString)
                ilike('cell', searchString)
            }
        }

        count = criteria.count()
        parents = criteria.list(max: params.max, offset: params.offset) {
            order(params.sort, params.order)
            order('id', params.order)
        }
    }

    def allMembers = [data: [], recordsTotal: count, recordsFiltered: count, draw: params.draw + 1]
    parents.each {
        def student = Student.findBySpridenId(it.studentEnumber)
        allMembers.data.push([
            it.id,
            it.lastName + ', ' + it.firstName,
            it.email,
            student?.getFullName(),
            it.studentEnumber,
            it.lastPaid.format("yy") + '-' + it.renewDate.format("yy"),
            it.cell,
            it.statusInd,
        ])
    }

    render(allMembers as JSON)

}

Answers

  • ignignoktignignokt Posts: 146Questions: 4Answers: 39

    In your code, it looks like line 54.

    recordsTotal will always be equal to the total results.
    recordsFiltered will always be the "recordsTotal" of the filter being applied.

    So if you have no filter, then you'd see something like recordsFiltered = 48, recordsTotal = 48. If you have a filter then you'd see something like recordsFiltered = 21, recordsTotal = 48.

  • Connorln3Connorln3 Posts: 6Questions: 3Answers: 0

    You are correct. The count that was being passed through was incorrect on some of my tables. count = Parent.count() was returning the total number of Parent objects, but in other tables I needed to change the count. Thanks!

This discussion has been closed.