javascript - Datatables - api.column().data() call on rendered column -
javascript - Datatables - api.column().data() call on rendered column -
my issue i'm trying "total" row @ bottom of datatable. row, $0 total. if alter api.column(4) api.column(3), adds column correctly, know works.
i think issue how i'm getting info column index 4 (item total). i'm setting data: null, because i'm rendering info multiplying cost , quantity together. i'm not sure why api.column(4).data() isn't getting rendered information.
$(document).ready(function() { editor = new $.fn.datatable.editor( { processing: true, seriverside: true, ajax: "datatables-1.10.0/extensions/editor-1.3.1/examples/php/test.php?pid=<? echo $pid ?>", table: "#pexpenses", fields: [ { label: "type:", name: "tbl_pexpenses.type", type: "select" }, { label: "cost:", name: "tbl_pexpenses.cost" }, { label: "quantity:", name: "tbl_pexpenses.quantity" }, { label: "description:", name: "tbl_pexpenses.description" }, { label: "peid:", name: "tbl_pexpenses.peid", type: "hidden" }, { label: "pid:", name: "tbl_pexpenses.pid", def: '<? echo $pid; ?>', type: "hidden" } ] } ); $('#pexpenses').datatable( { dom: "tfrtip", pagelength: -1, type: 'post', paging: false, info: false, idsrc: "tbl_pexpenses.peid", ajax: "datatables-1.10.0/extensions/editor-1.3.1/examples/php/test.php?pid=<? echo $pid ?>", columns: [ { data: "tbl_types.type_desc" }, { data: "tbl_pexpenses.description" }, { data: "tbl_pexpenses.cost" }, { data: "tbl_pexpenses.quantity" }, { data: null, render: function ( data, type, row ) { homecoming (data.tbl_pexpenses.cost*data.tbl_pexpenses.quantity); } } ], tabletools: { srowselect: "os", sswfpath: "../datatables-1.10.0/extensions/tabletools/swf/copy_csv_xls_pdf.swf", abuttons: [ { sextends: "editor_create", editor: editor }, { sextends: "editor_edit", editor: editor }, { sextends: "editor_remove", editor: editor }, "print", { "sextends": "collection", "sbuttontext": "save", "abuttons": [ "csv", "xls", "pdf" ]} ] }, "order": [[ 0, 'asc' ]], "drawcallback": function ( settings ) { var api = this.api(); var rows = api.rows( {page:'current'} ).nodes(); var last=null; api.column(0, {page:'current'} ).data().each( function ( group, ) { if ( lastly !== grouping ) { $(rows).eq( ).before( '<tr class="grouping" ><td colspan="5">'+group+'</td></tr>' ); lastly = group; } } ); }, initcomplete: function ( settings, json ) { editor.field( 'tbl_pexpenses.type' ).update( json.tbl_types ); }, footercallback: function ( row, data, start, end, display ) { var api = this.api(), data; // remove formatting integer info addition var intval = function ( ) { homecoming typeof === 'string' ? i.replace(/[\$,]/g, '')*1 : typeof === 'number' ? : 0; }; // total on pages info = api.column( 4 ).data(); total = data.length ? data.reduce( function (a, b) { homecoming intval(a) + intval(b); } ) : 0; // update footer $( api.column( 4 ).footer() ).html( '$'+ total ); } } ); // order grouping $('#example tbody').on( 'click', 'tr.group', function () { var currentorder = table.order()[0]; if ( currentorder[0] === 0 && currentorder[0] === 'asc' ) { table.order( [ 0, 'desc' ] ).draw(); } else { table.order( [ 0, 'asc' ] ).draw(); } } ); <table id="pexpenses" class="display" cellspacing="0" width="100%"> <thead> <tr> <th>type</th> <th>description</th> <th>cost</th> <th>quantity</th> <th>item total</th> </tr> </thead> <tfoot> <tr> <td> </td> <td> </td> <td> </td> <th style="text-align:right">total:</th> <th></th> </tr> <tr> <th>type</th> <th>description</th> <th>cost</th> <th>quantity</th> <th>item total</th> </tr> </tfoot>
// total on pages info = api.column( 4 ).cache('search'); total = data.length ? data.reduce( function (a, b) { homecoming intval(a) + intval(b); } ) : 0; // update footer $( api.column( 4 ).footer() ).html( '$'+ total ); } } );
} );
i had cache column right info it. calculates correctly.
javascript jquery jquery-datatables jquery-datatables-editor
Comments
Post a Comment