2

I am new to JQuery Data tables. I have a requirement where in i have to display only last ten entered records in a data table with no pagination or sorting.I am able to get the last ten records with the ajax call. but in the header and footer i have the record information. Right now if i have total 25 records and i am displaying only last 10, the table header/footer will show : Records 1 to 10 of 10. This is because i have a language tag which is below:

"language":{
   "info":  "Records _START_ to _END_ of _MAX_",
},

But my requirement is to display: Records 5 to 15 of 15 or 7 to 17 of 17.

i checked data tables website, they had these for info keywords :

This is info i got from data tables

but with _MAX_ i am not getting the total records also with _START_ and _END_ i am getting Records 1 to 10 of 10 always even if my record sequence number which is getting displayed in the table is 5 to 15

Any help is appreciated. Please ask questions if my description is not enough.

Here is my Data Table initialization code:

var Table = $('#MyDataTable').DataTable({

    "dom":'<i><"clear"><p><"bottomfmarg"f>t<i><"clear"><p>',
    responsive: false,
    "processing": true,
    "ajax":{
       "url":"URL",<%-- data will served via ajax request --%>
       "type":"POST"
    },  
    "deferRender": true,
    "columns": [
             { "data": "col1"},
             { "data": "col2"},
             { "data": "col3"} 
             ,{ "data": null,"defaultContent": "","orderable": false}
    ],
    "paging": false,
    "info": true,
    "ordering":true,
    "searching":false,
    "serverSide":false,
    "pagingType": "simple_numbers",
    "lengthChange": false,
    "pageLength":50, <%-- controls the pagination length --%>
    "autowidth":true,
    "language":{
       "emptyTable":     "No Records",
       "info":           "Records _START_ to _END_ of _MAX_",
       "infoEmpty":      "0 records",
       "infoFiltered":   "filtered from _MAX_ total Record(s)",
       "loadingRecords": "Loading Records",
       "infoPostFix":    "",
       "thousands":      ",",
       "search":         "Filter search results:",
       "zeroRecords":    "0 Records"
    }
});
ketan
  • 19,129
  • 42
  • 60
  • 98
Shrek
  • 39
  • 7
  • Here is my data Tables code: – Shrek Feb 05 '16 at 21:19
  • Possible duplicate of [How to modify row counts in DataTables](http://stackoverflow.com/questions/31938113/how-to-modify-row-counts-in-datatables) – Gyrocode.com Feb 05 '16 at 21:36
  • Thanks for that one. So initially i was pulling only 10 rows from database (AJAX call) thats y was not getting total correct. now when i have fixed my display of rows correct with infoCallback function. My page length is not working. when i set "pageLength":10, my table shows more than ten. i want to show only last 10 here in the table. – Shrek Feb 05 '16 at 22:50
  • 1
    You have paging disabled with `paging: false` that is why it shows all records. – Gyrocode.com Feb 06 '16 at 01:29
  • Thanks for that one . Again but the flip side I tried tht , but in my code when I enable it paging : true it shows my records in diff pages like pagination .. But I am sorry if I dint write this in my question but I wanna display one page with only the last ten records ... So paging = false dosent show the pagination <> hyperlinks's for pagination . – Shrek Feb 06 '16 at 02:16
  • I think you need to retrieve your data separately with `$.ajax` and then pass only last 10 records to jQuery DataTables via [`data`](http://datatables.net/reference/option/data) option while using `infoCallback`. – Gyrocode.com Feb 06 '16 at 02:47
  • Can you please elaborate this Gyrocode. – Shrek Feb 08 '16 at 14:24
  • See [this example](https://jsfiddle.net/9tspese4/). – Gyrocode.com Feb 08 '16 at 15:46

0 Answers0