Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 81916

Footer Feedback - Javascript Initialise code

$
0
0
  1. Use the Generator for Editor to create application server-side php.

  2. Edit/Add code from example: (Bottom of HTML or table.example.js file)

A. Javascript code from "Footer Feedback" example:

$(document).ready(function() {
$('#example').DataTable( {
"footerCallback": function ( row, data, start, end, display ) {
var api = this.api(), data;

        // Remove the formatting to get integer data for summation
        var intVal = function ( i ) {
            return typeof i === 'string' ?
                i.replace(/[\$,]/g, '')*1 :
                typeof i === 'number' ?
                    i : 0;
        };

        // Total over all pages
        total = api
            .column( 4 )
            .data()
            .reduce( function (a, b) {
                return intVal(a) + intVal(b);
            }, 0 );

        // Total over this page
        pageTotal = api
            .column( 4, { page: 'current'} )
            .data()
            .reduce( function (a, b) {
                return intVal(a) + intVal(b);
            }, 0 );

        // Update footer
        $( api.column( 4 ).footer() ).html(
            '$'+pageTotal +' ( $'+ total +' total)'
        );
    }
} );

} );

B. Code from table.example.js file

/*
* Editor client script for DB table example
* Created by http://editor.datatables.net/generator
*/

(function($){
$(document).ready(function() {
var editor = new $.fn.dataTable.Editor( {
ajax: 'php/table.example.php',
table: '#example',
fields: [
{
"label": "First name:",
"name": "first_name"
},
{
"label": "Last name:",
"name": "last_name"
},
{
"label": "Position:",
"name": "position"
},
{
"label": "Office:",
"name": "office"
},
{
"label": "Salary:",
"name": "salary"
}
]
} );

var table = $('#example').DataTable( {
    dom: 'Bfrtip',
    ajax: 'php/table.example.php',
    columns: [
        {
            "data": "first_name"
        },
        {
            "data": "last_name"
        },
        {
            "data": "position"
        },
        {
            "data": "office"
        },
        {
            "data": "salary"
        }
    ],
    select: true,
    lengthChange: false,
    buttons: [
        { extend: 'create', editor: editor },
        { extend: 'edit',   editor: editor },
        { extend: 'remove', editor: editor }
    ]
} );

} );

}(jQuery));

Question: Where would I add or edit "Footer Feedback" example code? Do I edit the table.example.js or add it to the bottom on the HTML file?

If I add the code to the table.example.js file I receive the error:

DataTables warning: table id=example - Cannot reinitialise DataTable. For more information about this error, please see http://datatables.net/tn/3.


Viewing all articles
Browse latest Browse all 81916

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>