Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- https://datatables.net/examples/api/row_details.html
- function misAlbaranes(Finicio, Ffin, Tipo) {//Esta función es la que ejecuta la tabla de albaranes.
- var parametros = {
- "Finicio": Finicio,
- "Ffin": Ffin,
- "Tipo": Tipo,
- };
- $.fn.dataTable.moment('DD/MM/YYYY');
- tblAlbaranes = $('#tbl_Albaranes').DataTable({
- stateSave: true, //Guarda el estado de la tabla, orden, pagina etc
- colReorder: true,
- "autoWidth": false,
- "processing": true,
- "destroy": "true",
- "pagingType": "simple",
- "responsive": {
- "details": false,
- },
- "ajax": {
- "data": parametros,
- "url": "php/AgrApp/albaranes.php",
- "type": "POST",
- "dataSrc": "",
- },
- "columns": [
- {
- "data": "id",
- },{
- "defaultContent": "<button type='button' " title="Ver detalle" class='linAlb btn btn-primary btn-xs '><span class='glyphicon glyphicon-zoom-in'></span></button>",
- "responsivePriority": "1",
- "width": "3%",
- },{
- "data": "nro_ser",
- "responsivePriority": "2"
- }, {
- "data": "fac_ser"
- }, {
- "data": 'emp',
- render: function (data, type, row) {
- emp = devuelveEmpresa(data)
- return emp;
- }
- }, {
- "data": "fch",
- "responsivePriority": "1"
- }, {
- "data": "finca_name"
- }, {
- "data": "pso_net_real",
- "responsivePriority": "3"
- }, {
- "data": "imp",
- "responsivePriority": "4"
- }, {
- "data": "dto_com"
- }, {
- "data": "dto_trp"
- }, ]
- });
- $('#tbl_Albaranes tbody').off('click', 'button.linAlb');
- $('#tbl_Albaranes tbody').on('click', 'button.linAlb', function () {
- var tr = $(this).closest('tr');
- var row = tblAlbaranes.row( tr );
- var open = row.child.isShown();
- var idLinAlb = tblAlbaranes.row($(this).parents("tr")).data();
- tblAlbaranes.rows().every( function ( rowIdx, tableLoop, rowLoop ) {
- if (this.child.isShown()) {
- this.child.hide();
- $(this.node()).removeClass('shown');
- }
- });
- if(!open){
- mvt_com_x_alb(idLinAlb['id'], function (tablinAlb) {
- row.child(tablinAlb).show(); //Esta escondido, llamo a la función
- tr.addClass('shown');
- });
- }
- });
- }
- function mvt_com_x_alb(idAlb,callbackFunction){
- var parametros = {
- "idAlb": idAlb,
- };
- $.ajax({
- data: parametros,
- url: "php/AgrApp/lin_alb.php",
- type: "POST",
- success: function (data) {
- objJson = JSON.parse(data);
- var tablinAlb = '<table id="tbl_LinAlb" class="display responsive no-wrap" style="width:100%" ><thead><tr HEIGHT="3"> <td BGCOLOR="#7c979e"><font color="white">Albarán:</font></td> <td BGCOLOR="#7c979e" ><font color="white">Producto:</font></td><td BGCOLOR="#7c979e" class = "text-right"><font color="white">Fecha:</font></td><td BGCOLOR="#7c979e" ><font color="white">Certificado:</font></td><td BGCOLOR="#7c979e" class = "text-right"><font color="white">Bultos:</font></td><td BGCOLOR="#7c979e" class = "text-right"><font color="white">Kilos:</font></td><td BGCOLOR="#7c979e" class = "text-right"><font color="white">Precio:</font></td><td BGCOLOR="#7c979e" class = "text-right"><font color="white">Importe:</font></td></tr>'
- + '</thead>' + '<tbody>';
- $.each(objJson, function (i, item) {
- tablinAlb += '<tr style="cursor: pointer;"> <td>' + objJson[i].alb_ser + '</td><td >' + objJson[i].name + '</td><td class = "text-right">' + objJson[i].fch + '</td><td>' + objJson[i].cert + '</td><td class = "text-right">' + objJson[i].cnt + '</td><td class = "text-right">' + objJson[i].pso_net_real + '</td><td class = "text-right">' + objJson[i].pre + '</td><td class = "text-right">' + objJson[i].imp + '</td></tr>';
- });
- tablinAlb += '</tbody><tfoot><tr HEIGHT="3"> <td BGCOLOR="#7c979e"></td> <td BGCOLOR="#7c979e" ></td><td BGCOLOR="#7c979e" class = "text-right"></td><td BGCOLOR="#7c979e" ></td><td BGCOLOR="#7c979e" class = "text-right"></td><td BGCOLOR="#7c979e" class = "text-right" ></td><td BGCOLOR="#7c979e" class = "text-right"></td><td BGCOLOR="#7c979e" class = "text-right"></td></tr></tfoot></table>' ;
- callbackFunction(tablinAlb);
- $(document).ready( function () {
- tblLinALb=$('#tbl_LinAlb').DataTable({
- lengthMenu: [10, 50, 250, 1000],
- "destroy": true,
- stateSave: true,
- "autoWidth": false,
- "processing": true,
- "responsive": true,
- "paging": true,
- "ordering": true,
- "info": true,
- "details": true,
- "searching": false,
- "pagingType": "simple",
- });
- });
- }
- });
- }
Add Comment
Please, Sign In to add comment