FrenkyB
FrenkyB

Reputation: 7207

JQuery DataTables get info message

Is it possible to get this info message from data tables through some public method:

Showing 1 to 8 of 35 entries (filtered from 104 total entries)

What I've found is this:

$("#myTable_info").text()

I can get text through this and hide original DIV with info message. But I guess there is some public method through which I can read info message? I am asking this because I want my own control with info message and not use default one, in the lower left corner.

Upvotes: 0

Views: 648

Answers (2)

Rajshekar Reddy
Rajshekar Reddy

Reputation: 19007

You will get the object with the page details using a method from the API called .page.info()

So to get this information use one of the methods as described below.


Using .DataTable()

1) $('#myTable_info').DataTable().page.info();

I ran this in the datatables main landing page. And here is the result

enter image description here

2) you can save the DataTable() object into a variable when you apply the plugin and then use the .page.info() on it.

 var myDataTable = $('#myTable_info').DataTable(); // you apply the plugin here.
 var pageInfoObject = myDataTable.page.info();

Using .dataTable()

3) when you apply the plugin using .dataTable() then to get the page infor you must use the api(). like below

$('#myTable_info').dataTable().api().page.info();

4) Or save into a variable and then use the variable to get the info like this.

var myDataTable= $('#myTable_info').dataTable();
var info = myDataTable.api().page.info();

Edit 1) after your comment on the other answer

I just want to show info message in my own DIV. I know how to manipulate it, just don't know how not to use default DIV where this message is displayed (lower left corner)

What you are looking for is to change the datatables DOM structure.

it would be better if you take some time and understand the logic in the above mention link.

Example : If you want to place the page info on top of the table in a seperate div then this is how you do it. Example here Basic Initialization

   $('#myTable_info').DataTable( {
        "dom": '<"top"i>rt<"bottom"flp><"clear">'
    } );

Upvotes: 0

Dipali Vasani
Dipali Vasani

Reputation: 2536

If you want to customize info messages you can go through Language option of DataTable. Info is used for customizing message.

here is the example

$('#example').dataTable( {
  "language": {
    "info": "Showing page _PAGE_ of _PAGES_",
    "infoEmpty":      "Showing 0 to 0 of 0 entries",
    "infoPostFix":    "",
    "infoFiltered":   "(filtered from _MAX_ total entries)",
  }
} );

UPDATE :

for public method to get page info :

var table = $('#example').dataTable();
var info = table.api().page.info();

var table = $('#example').DataTable(); 
var info = table .page.info()

Upvotes: 2

Related Questions