Totals Row broken Pagination

Totals Row broken Pagination

NickyJNickyJ Posts: 1Questions: 0Answers: 0
edited November 2011 in DataTables 1.8
Firstly I have to say this table plugin is great, great functionality.

I have a server side script table, with additional date range filters. All working fine. I have since added the footer callback to total a column, just per example http://datatables.net/examples/advanced_init/footer_callback.html

Now this breaks the pagination as I get a Javascript error of

[quote]aaData[aiDisplay[i]] is undefined [/quote]

Using : [code]
"fnFooterCallback": function ( nRow, aaData, iStart, iEnd, aiDisplay ) {

var iTotalMarket = 0;
for ( var i=0 ; i

Replies

  • allanallan Posts: 63,691Questions: 1Answers: 10,500 Site admin
    Hi NickyJ

    > Firstly I have to say this table plugin is great, great functionality.

    Thanks!

    > Feel I may be missing something pretty obvious, any advice appreciated.

    Its not that obvious actually :-). The example above works for client-side processing since DataTables stores a cache of all data on the client-side (which is what aaData is, and aiDisplay is pointing at). This doesn't work on server-side processing since there is no client-side store of the full data set - only the current page. This all you need to do here is loop over aaData - since that's all the data for the current page.

    [code]
                for ( var i=0 ; i
  • gpanggpang Posts: 18Questions: 0Answers: 0
    I have Ajax data source but I got [object Object] error for aaData[n], where n is an integer, as 1. If I do aaData[n][n] as in aaData[1][1], the error is " aaData[1] is undefined". Would you give some advice and I will appreciate it.

    George
  • allanallan Posts: 63,691Questions: 1Answers: 10,500 Site admin
    edited May 2012
    > aaData[n]

    I'm not sure where where aaData[n] is, as it isn't in the above code. Can you link me to your page please?

    Allan
  • gpanggpang Posts: 18Questions: 0Answers: 0
    edited May 2012
    Thank you Allan for the reply. The page is an internal page so I can't display here, but the test code snippet is as below, and it's pretty simple:
    [code]
    var oTable = $('#example').dataTable({

    "sAjaxSource" : "someController.someAction",

    "fnFooterCallback": function (nFoot, aaData, iStart, iEnd, aiDisplay ) {

    alert(aaData[1]);
    },
    "aoColumns" : [
    {
    "mDataProp" : "field1"
    },
    {
    "mDataProp" : "field2",
    "sWidth" : "20%",
    "sClass" : "center"
    },
    {
    "mDataProp" : "field3",
    "sWidth" : "20%",
    "sClass" : "center"
    },
    {
    "mDataProp" : "field4",
    "sWidth" : "20%",
    "sClass" : "center"
    }
    ]

    });
    [/code]

    Looks like I missed something, and the aaData[1] will return [object Object]. By the way, I enjoy this plugin(Datatables) so much. Thank you.
  • allanallan Posts: 63,691Questions: 1Answers: 10,500 Site admin
    > the aaData[1] will return [object Object]

    It would do :-). Its an array of arrays or an array of objects depending on your data source. So aaData[1] is just the second element. I'd suggest you use console.log( aaData ); rather than alert() as that will let you actually see what is in the object.

    Allan
  • gpanggpang Posts: 18Questions: 0Answers: 0
    Thanks Allan. My data source is an array of objects, so I tried accessing the cell element, which is at my interest, in a datatable by aaData[1].fieldName, but I still get "aaData[1] is undefined" error.
  • allanallan Posts: 63,691Questions: 1Answers: 10,500 Site admin
    What do you get if you put in console.log( aaData.length )?

    Allan
  • gpanggpang Posts: 18Questions: 0Answers: 0
    Hi Allan, the output on console for console.log( aaData.length ) is:
    [quote]
    0
    GET http://localhost:9000/someController/someAction?_=1336032307777 200 OK 153ms
    332
    [/quote]

    It return me a correct count. And if I do console.log( aaData[1] ), this will get returned:
    [quote]
    Object { field1="value1", field2="value2", field3="value3", .....}
    [/quote]

    And those fields and values are all correct.

    But if I do console.log( aaData[1].field1] ), it will return:
    [quote]
    aaData[1] is undefined
    [/quote]

    Thank you!
  • gpanggpang Posts: 18Questions: 0Answers: 0
    Obviously the data are all there in the json object "aaData[1]", I just suffer not being able to get them like using aaData[1][1] or aaData[1].field1, both will return me "aaData[1] is undefined". The table actually displays the data perfectly. Any of your input is much appreciated.
  • gpanggpang Posts: 18Questions: 0Answers: 0
    Would somebody help on this issue? It will be much appreciated!
  • allanallan Posts: 63,691Questions: 1Answers: 10,500 Site admin
    > aaData[1].field1

    From your description that looks like it should work to me. I'm fraud that to offer any further assistance I'd need to be able to actually see the page, so I can see what is going wrong with it.

    Allan
  • gpanggpang Posts: 18Questions: 0Answers: 0
    edited May 2012
    Hi Alan,

    I used [code]oTable.fnGetData(aiDisplay[x],y)[/code], where x, y are integers, to work around this problem. But still want to know how I can't use aaData[x].field, since I have the aaData, at least for the current page.
  • allanallan Posts: 63,691Questions: 1Answers: 10,500 Site admin
    As far as I can see you should be able to use aaData[x].field. As I mentioned, I think I would need to see an example of the issue to debug it any further.

    Allan
  • gpanggpang Posts: 18Questions: 0Answers: 0
    Does it help if I send you the page source? Thank you.

    George
  • allanallan Posts: 63,691Questions: 1Answers: 10,500 Site admin
    edited May 2012
    Given that its an Ajax data issue I think I'd need to see the whole page in action, not just the HTML / JS source (since that would be missing the data).

    Allan
This discussion has been closed.