Get total records of a Jquery Datatable

Asked

Viewed 1,231 times

0

I need to make a comparison with the total value of records that exist in the database, in a given table. I could get this value via PHP, and pass to Javascript, during page rendering, however, records can be added/deleted dynamically, and then the total records can be changed. In fact, what interests me is to make a comparison with the total values displayed (or that can be displayed in the case of pagination), because for the user, the table reflects the bank.

I don’t think it’s a good solution to create an Action in the controller, just to answer a request for this value, since "theoretically" I have it available.

The datatable configuration:

    $("#datagrid").DataTable({
        oLanguage: DT_PTBR,
        dom: 'l<"toolbar-h"fT>rtip',
        "ajax": {
            "url": "/datatable-data",

As the loading is dynamic, the solution of counting table rows, does not work.

I researched for a solution, and found suggestions to get the value I want that way:

oTable.fnSettings(). fnRecordsTotal()

In this case, it gave no clues as to how the oTable could be obtained. So I searched for a way to obtain this "object", and apparently it is obtained that way:

var oTable = $("#datagrid").DataTable({

But when using such an object, in the above solution, an error occurs ("fnSettings", not a function). I tried that way too:

 $("#datagrid").DataTable().fnSettings().fnRecordsTotal()

and

  $("#datagrid").DataTable().fnRecordsTotal()

But to no avail.

1 answer

-2

utilize

$("#datagrid").dataTable().fnSettings().fnRecordsTotal()

Browser other questions tagged

You are not signed in. Login or sign up in order to post.