How to generate sEcho ??

How to generate sEcho ??

nathanseonathanseo Posts: 7Questions: 2Answers: 0

Totally blown away by how useful datatables is, however i'm having an issue generating the correct json format in codeigniter.

I'm trying to get the total (sum) of a column but it always returns NaN, but i've noticed my json format appears different, for example.

The sEcho format should look like this

"sEcho": 1,
    "iTotalRecords": 2,
    "iTotalDisplayRecords": 2,
    "aaData": []

However, I'm receiving a format like this

"draw": 0,
    "recordsTotal": 38,
    "recordsFiltered": 38,
    "data": []

Answers

  • allanallan Posts: 63,754Questions: 1Answers: 10,509 Site admin

    Hi,

    The first format you show is the legacy format. The second is the current. To force one format or the other see the server-side processing documentation.

    I would suggest using the new format if you can rather than the legacy format.

    Allan

  • nathanseonathanseo Posts: 7Questions: 2Answers: 0

    Ok i'm using 1.9 so I guess thats ok, but i'm gonna have to look into different methods for the footercallback and sum, do you guys offer development for such requests?

  • ThomDThomD Posts: 334Questions: 11Answers: 43

    If you are new to Dt, you really want to move up to 1.10 and the current syntax. Sticking with the legacy syntax will limit the amount of community based support you can get.

    What do you want to do with the footercallback and sums? Did you look at the example on column sums?

  • nathanseonathanseo Posts: 7Questions: 2Answers: 0

    Hi ThomD, I just want to get the total sum of columns in range and page, I've checked out tutorials and guides but i'm still getting NaN, my code currently looks like this..

    "fnFooterCallback": function ( nRow, aoData, iStart, iEnd, aiDisplay ) {
                    // Total col 4
                        var iTotalRecords = 0;
                        for ( var i=0 ; i<aoData.length ; i++ )
                        {
                            iTotalRecords += aoData[i][4]*1;
                        } 
                        // Modify the footer row to match what we want
                        var nCells = nRow.getElementsByTagName('th');
                        nCells[4].innerHTML = parseFloat(iTotalRecords * 100);
                    }
    

    Returning anything other than NaN would be a start, i've tried parseInt & Number also

  • nathanseonathanseo Posts: 7Questions: 2Answers: 0

    Ok I've done it!!

    I changed this -> iTotalRecords += aoData[i]['deposit_amount']*1;

    Cheers guys, great stuff

This discussion has been closed.