Guest User

Untitled

a guest
Jun 13th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.49 KB | None | 0 0
  1. https://datatables.net/examples/api/row_details.html
  2.  
  3. function misAlbaranes(Finicio, Ffin, Tipo) {//Esta función es la que ejecuta la tabla de albaranes.
  4. var parametros = {
  5. "Finicio": Finicio,
  6. "Ffin": Ffin,
  7. "Tipo": Tipo,
  8. };
  9. $.fn.dataTable.moment('DD/MM/YYYY');
  10. tblAlbaranes = $('#tbl_Albaranes').DataTable({
  11. stateSave: true, //Guarda el estado de la tabla, orden, pagina etc
  12. colReorder: true,
  13. "autoWidth": false,
  14. "processing": true,
  15. "destroy": "true",
  16. "pagingType": "simple",
  17. "responsive": {
  18. "details": false,
  19. },
  20.  
  21. "ajax": {
  22.  
  23. "data": parametros,
  24. "url": "php/AgrApp/albaranes.php",
  25. "type": "POST",
  26. "dataSrc": "",
  27. },
  28.  
  29. "columns": [
  30. {
  31. "data": "id",
  32. },{
  33. "defaultContent": "<button type='button' " title="Ver detalle" class='linAlb btn btn-primary btn-xs '><span class='glyphicon glyphicon-zoom-in'></span></button>",
  34. "responsivePriority": "1",
  35. "width": "3%",
  36. },{
  37. "data": "nro_ser",
  38. "responsivePriority": "2"
  39. }, {
  40. "data": "fac_ser"
  41. }, {
  42. "data": 'emp',
  43. render: function (data, type, row) {
  44. emp = devuelveEmpresa(data)
  45. return emp;
  46. }
  47. }, {
  48. "data": "fch",
  49. "responsivePriority": "1"
  50. }, {
  51. "data": "finca_name"
  52. }, {
  53. "data": "pso_net_real",
  54. "responsivePriority": "3"
  55. }, {
  56. "data": "imp",
  57. "responsivePriority": "4"
  58. }, {
  59. "data": "dto_com"
  60. }, {
  61. "data": "dto_trp"
  62. }, ]
  63. });
  64.  
  65. $('#tbl_Albaranes tbody').off('click', 'button.linAlb');
  66. $('#tbl_Albaranes tbody').on('click', 'button.linAlb', function () {
  67.  
  68. var tr = $(this).closest('tr');
  69. var row = tblAlbaranes.row( tr );
  70. var open = row.child.isShown();
  71. var idLinAlb = tblAlbaranes.row($(this).parents("tr")).data();
  72. tblAlbaranes.rows().every( function ( rowIdx, tableLoop, rowLoop ) {
  73. if (this.child.isShown()) {
  74. this.child.hide();
  75. $(this.node()).removeClass('shown');
  76. }
  77. });
  78.  
  79. if(!open){
  80. mvt_com_x_alb(idLinAlb['id'], function (tablinAlb) {
  81. row.child(tablinAlb).show(); //Esta escondido, llamo a la función
  82. tr.addClass('shown');
  83. });
  84. }
  85. });
  86. }
  87.  
  88. function mvt_com_x_alb(idAlb,callbackFunction){
  89.  
  90. var parametros = {
  91. "idAlb": idAlb,
  92. };
  93.  
  94. $.ajax({
  95. data: parametros,
  96. url: "php/AgrApp/lin_alb.php",
  97. type: "POST",
  98. success: function (data) {
  99. objJson = JSON.parse(data);
  100. 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&aacute;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>'
  101. + '</thead>' + '<tbody>';
  102. $.each(objJson, function (i, item) {
  103. 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>';
  104. });
  105. 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>' ;
  106.  
  107. callbackFunction(tablinAlb);
  108.  
  109. $(document).ready( function () {
  110. tblLinALb=$('#tbl_LinAlb').DataTable({
  111. lengthMenu: [10, 50, 250, 1000],
  112. "destroy": true,
  113. stateSave: true,
  114. "autoWidth": false,
  115. "processing": true,
  116. "responsive": true,
  117. "paging": true,
  118. "ordering": true,
  119. "info": true,
  120. "details": true,
  121. "searching": false,
  122. "pagingType": "simple",
  123. });
  124. });
  125.  
  126. }
  127. });
  128. }
Add Comment
Please, Sign In to add comment