Row Total and Column Total calculation that gives rise to error

Row Total and Column Total calculation that gives rise to error

DT ProgerDT Proger Posts: 18Questions: 5Answers: 0

Please click the link below to get a feel for what I was trying to do:

http://58.64.211.82/Ed/examples/advanced/linkTable4.html

If you have just clicked the link and if it does load properly (in case it doesn't please feedback and let me know), you would have immediately got what I was trying to do.

The right-most column (column 9) is a computed column showing price * qty, and the "Total" field at the right-most of the footer is obviously meant to be the sum of all the values in column 9, which clearly doesn't work due to the error box that pops up on page load.

The obvious question is: what is the cause of the error box that pops up on page load and how to get around that?

The strange thing is that the page does load and work properly, except for the grand total at the footer of course, without any error message after I commented out the footerCallback part of the Datatable initialization, as testified by the link below:

http://58.64.211.82/Ed/examples/advanced/linkTable5.html

Please could you let me know what I need to do to fix linkTable4.html so that I can get that grand total at the footer?

Thank you in advance for your response.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,488Questions: 1Answers: 10,467 Site admin
    Answer ✓

    DataTables warning: table id=example - Requested unknown parameter 'computed_total' for row 0, column 9.

    There is no computed_total in your data source object for the rows which is why you are getting that error. Set columns.data for that column to be null and just let it use the rendered above. Note also you can't define columns.render twice - only once!

    However, that isn't the issue that you describe above - the issue there is:

    .column( 9, { page: 'current'} )
                    .data()
    

    You are trying to get the data from column index 9, which as the code stands points to the existent property computed_total. Even if you make the above change column().data() is not the correct one to use since it doesn't have the data you want in the original source object.

    You need to use the cells().render() method to get the rendered data. For example:

    api.cells( null, 9, {page:'current'} ).render( 'display' )
    

    Allan

  • DT ProgerDT Proger Posts: 18Questions: 5Answers: 0

    Hi Alan, truly grateful for your expert advice. As always, your solution works perfectly.

This discussion has been closed.