i'm new using jquery datatables plugin, it's great, need make row grouping , make own solution, isn't optimal, wanna ask advice/tips because app blocks when try use column filter , takes long load (i optimize mysql query).
i'm using cakephp 2.3 pendientes.ctp file looks 
<?php $this->assign('icono', 'ico-files'); $this->assign('titulo', 'facturas pendientes de cobro'); ?> <?php echo $this->form->create( array('inputdefaults' => array('label' => false,'div' => false))); ?> <div class="row-fluid"> </div> <div class="row-fluid"> <div class="block"> <div class="data-fluid"> <table class="table table-hover fptablefvcp2 lcnp" cellpadding="0" cellspacing="0" width="100%"> <thead> <tr> <th class="elim">cliente</th> <th width="6%">fecha</th> <th>#</th> <th>moneda</th> <th>monto total</th> <th>saldo</th> </tr> </thead> <thead> <tr class="filtros_busqueda"> <td class="elim"><input type="text" name="search_cliente" placeholder="filtrar" class="search_init"></td> <td><input type="text" name="search_numero" placeholder="filtrar" class="search_init"></td> <td><input type="text" name="search_fecha" id="date-range" placeholder="filtrar" class="search_init"></td> <td><input type="text" name="search_moneda" id="date-range" placeholder="filtrar" class="search_init"></td> <td><input type="text" name="search_monto" placeholder="filtrar" class="search_init"></td> <td><input type="text" name="search_saldo" placeholder="filtrar" class="search_init"></td> </tr> </thead> <tbody> <?php $i = 0; foreach ($data $d):?> <tr> <td class="elim" id="ordenador"><?php echo $d['cliente']['nombretitular'].'('.$d['cliente']['razonsocial'].')';?></td> <td><?php echo implode('/', array_reverse(explode('-', $d['comprobantesventa']['fecha'])));?></td> <td><?php echo $this->html->link( $d['comprobantesventa']['numero'], array('action' => 'edit/'.$d['comprobantesventa']['id'].'/'.$d['tipocomprobante']['id']));?></td> <td class="monedass"><?php echo $d['moneda']['moneda'];?></td> <td style='text-align:right;' class="montoss"><?php echo number_format ( $d['comprobantesventa']['monto_total'], 2, ',', '');?></td> <td style='text-align:right;' class="saldoss"><?php echo number_format ( $d['comprobantesventa']['saldo'], 2, ',', '');?></td> </tr> <?php endforeach;?> </tbody> </table> <?php if (!empty($data)) { foreach ($data $d): ?> <!--aca comienza el detalle de la tabla--> <div id="row<?php echo $d['comprobantesventa']['id'];?>" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="mymodallabel" aria-hidden="true" style="margin-left:300px; width:900px; height:300px;"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button> <h4 id="mymodallabel">datos del comprobante <?php echo $d['tipocomprobante']['abreviacion'].'-'. $d['comprobantesventa']['numero']; ?></h4> </div> <div class="row-fluid"> <table class="table" cellpading="0" cellspacing="0" width="100%"> <thead> <tr> <th>tipo documento</th> <th>artículo</th> <th>cantidad</th> <th>monto</th> <th>subtotal</th> </tr> </thead> <tbody> <?php foreach ($d['comprobantesventadetalle'] $dd) { echo "<tr>"; echo "<td>". $dd['tipo_documento']." - #".$dd['documento_numero']."</td>"; echo "<td>". $dd['articulo']['0']['articulo']['nombre']."</td>"; echo "<td style='text-align:right;'>". number_format ( $dd['cantidad'], 2, ',', '')."</td>"; echo "<td style='text-align:right;'>". $d['moneda']['moneda']. " " . number_format ( $dd['monto'], 2, ',', '.')."</td>"; echo "<td style='text-align:right;'>". $d['moneda']['moneda']. " " . number_format ( $dd['monto'] * $dd['cantidad'], 2, ',', '.')."</td>"; echo '</tr>'; } ?> </tbody> </table> </div> <div class="modal-footer"> <button class="btn btn-warning" data-dismiss="modal" aria-hidden="true">cerrar</button> </div> </div> <!--fin del detalle de la tabla--> <?php endforeach; } ?> </div> </div> </div> <script> columnas_sort = [ null, { "stype": "date-uk"}, null, null, { "stype": "currency"}, { "stype": "currency"}]; $(document).ready(function () { $(".filtros_busqueda").show(); if ($(".fptablefvcp2").length > 0) { var fctable = $(".fptablefvcp2").datatable({bsort: true, bautowidth: true, "idisplaylength": 50, "alengthmenu": [ 50, 100], // can removed basic 10 items per page "spaginationtype": "full_numbers", "sdom": 't<"clear">lfrtip', "otabletools": { "sswfpath": "../js/plugins/datatables/swf/copy_csv_xls_pdf.swf", "abuttons": [ { "sextends": "print", "sbuttontext": "imprimir", }, { "sextends": "pdf", "sbuttontext": "guardar pdf", "spdfmessage": "documento", "spdforientation": "landscape" }, { "sextends": "xls", "sbuttontext": "guardar excel" } ] }, "aocolumns": columnas_sort, //"aocolumndefs": [{"bsortable": false, "atargets": []},], version original "aocolumndefs": [{"bsortable": true, "atargets": []},], //daniel 01062015 //agregando callback daniel 01062015 "order": [[ 0, 'current' ]], "fndrawcallback": function ( osettings ) { var api = this.oapi; var annodes = $('#ordenador', api._fngettrnodes( osettings )); var annodes2 = api._fngettrnodes( osettings ); var total=$(annodes).length; var last=null; var band=true; var cont=0; var acum=1; var saldos=0; var monedas="$"; var pesos=0; var dolares=0; var euros=0; $( annodes).each( function (index){ cont=cont+1; acum=acum+1; if (last !== $(this).text()){ if (band){ // console.log($(this).text()); $('#ordenador',annodes2).eq( index ).closest('tr').before( '<tr class="group"><td class="fondos" colspan="5">'+ $(this).text() +'</td></tr> ' ); band=false; } else{ cont=cont-1; var auxiliar=last.split("(",1); $('#ordenador',annodes2).eq( index ).closest('tr').before( '<tr class="totales"><td colspan="5"> el total del cliente ' + auxiliar + ' es ' + saldos +' '+ monedas + '</td></tr> <tr class="group"><td class="fondos" colspan="5">'+ $(this).text() +'</td></tr> ' ); saldos=0; } if(total < acum){ cont=cont+1; monedas=$('#ordenador',annodes2).eq( index ).siblings('.monedass').text(); saldos=saldos+parsefloat($('#ordenador',annodes2).sort().eq( index ).siblings('.saldoss').text()); if (monedas=="$"){ pesos=pesos+saldos; } if (monedas=="u$s"){ dolares=dolares+saldos; } if(monedas=="euros"){ euros=euros+saldos; } var auxiliar2=$(this).text().split("(",1); $('#ordenador',annodes2).sort().eq( total-1 ).closest('tr').after( '<tr class="totales"><td colspan="5"> el total del cliente ' + auxiliar2 + ' es '+saldos +' '+monedas+'</td></tr> <tr class="totales"><td colspan="5"> el total general en $ es ' + pesos + '</td></tr> <tr class="totales"><td colspan="5"> el total general en u$s es ' + dolares + '</td></tr><tr class="totales"><td colspan="5"> el total general en euros es ' + euros + '</td></tr> ' ); } // console.log(acum); last=$(this).text(); } monedas=$('#ordenador',annodes2).eq( index ).siblings('.monedass').text(); saldos=saldos+parsefloat($('#ordenador',annodes2).sort().eq( index ).siblings('.saldoss').text()); if (monedas=="$"){ pesos=pesos+saldos; } if (monedas=="u$s"){ dolares=dolares+saldos; } if(monedas=="euros"){ euros=euros+saldos; } }); $(".fondos").css("background-color","#ddd !important"); $(".elim").hide(); } //fin callback 01062015 }); //$(".eliminar").remove(); //agregando el order 01062015 para que cuando se haga click en el area ordene todo $(".dttt_button_print").on('click',function(){ $(".filtros_busqueda").hide(); window.print(); } ); //fin de order 01062015 $("thead input").keyup(function () { fctable.fnfilter(htmlencode(this.value), $("thead input").index(this)); }); $("thead input").each(function (i) { if (this.value != "") { fctable.fnfilter(htmlencode(this.value), $("thead input").index(this)); //fctable.fndraw(); } }); $("thead input").focus(function () { if (this.classname == "search_init") { this.classname = ""; fctable.fndraw(); } }); $("thead input").blur(function (i) { if (this.value == "") { this.classname = "search_init"; fctable.fndraw(); } }); } }); </script>
esto: var total=$(annodes).length; var last=null; var band=true; var cont=0; var acum=1;
var saldos=0; var monedas="$"; var pesos=0; var dolares=0; var euros=0;
lo cambias esto:
var obj = { total: $(annodes).length, last: null, band: true, cont: 0, acum: 1, saldos: 0, monedas: "$", pesos: 0, dolares: 0, euros: 0 };
Comments
Post a Comment