Dynamically setting paging info on initialisation

Dynamically setting paging info on initialisation

ashmanashman Posts: 6Questions: 0Answers: 0
edited December 2013 in General
Hi all,

I have a very special requirement where I need to manually set the paging information displayed in datatables ("Showing x to y of z entries").
I discovered that I can use the plugin fnPagingInfo to get the data I need, and combine this with the datatables oLanguage/sInfo initialisation parameter (and so use my variable instead of the _END_ variable). So far so good.

I am struggling with passing in the variable from fnPagingInfo...this doesn't seem to work, and I am not sure what I am doing wrong. The code:

var oTable=$('#myTable').dataTable({
"oLanguage": { "sInfo": "Showing _START_ to "+this.fnPagingInfo().iTotal+" of _TOTAL_ entries"},
...

I am unable to get the total number through, and I get a javascript error...basically "this.fnPagingInfo().iTotal" is not working in this context (I do have the fnPagingInfo plug in included and am using it on the same page in other places without any errors).

Any ideas? It may be that I am using "this" incorrectly here? I have tried this without "this" , but I am getting the same result.

Thank you!

Replies

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395
    What number are you trying to replace _END_ with?
  • ashmanashman Posts: 6Questions: 0Answers: 0
    I am using the iTotal variable from the fnPagingInfo plugin which returns the total number of rows displayed on the current page.
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    You want to use the fnInfoCallback option which will let you specify absolutely what will go into the information box and should require the use of the plug-in (although you could still use it id you want).

    Your code doesn't work above since it is evaluated in the context of the function there the DataTable is initialised and run at that time only. It is not re-evaluated on every draw - that's what fnInfoCallback is used for :-)

    Allan
  • ashmanashman Posts: 6Questions: 0Answers: 0
    Thanks Allan...yes, I see that is exactly what I need!
This discussion has been closed.