Merge Inicialization and Funtions

Merge Inicialization and Funtions

kotushakotusha Posts: 3Questions: 1Answers: 0

I have two scripts that u need two merge for inicialization, and my third script is a click function, I can not get them two work property in one script. Please help me. Thank you.

Script 1

$(document).ready(function() { $('#TableRecords').DataTable( { "language": { "lengthMenu": "Despliega _MENU_ registros por pagina", "zeroRecords": "Ningun registro fue encontrado", "info": "Mostrando pagina _PAGE_ de _PAGES_", "infoEmpty": "Ningun Registro Disponible", "infoFiltered": "(Filtrado de _MAX_ registros totales)", "loadingRecords": "Cargando...", "processing": "Procesando...", "search": "Busqueda:", "paginate": { "first": "Primero", "last": "Ultimo", "next": "Siguiente", "previous": "Anterior" } } } ); } );

Script 2

$(document).ready(function() { $('#TableRecords').DataTable( { "columnDefs": [ { "targets": [ 1 ], "visible": false, "searchable": false }, { "targets": [ 2 ], "visible": false } ] } ); } );

Script 3

$(document).ready(function() { var table = $('#TableRecords').DataTable(); $('#TableRecords tbody').on('click', 'tr', function () { var data = table.row( this ).data(); document.getElementsByName("OriDes_ID")[0].value = data[0]; document.getElementsByName("OriDes_Ciudad")[0].value = data[2]; } ); } );

Answers

  • allanallan Posts: 63,760Questions: 1Answers: 10,510 Site admin

    You should initialise a DataTable only once. See the options section of the manual for an example on how you can merge multiple configuration objects.

    Allan

  • kotushakotusha Posts: 3Questions: 1Answers: 0

    I try to merge them like this but it did not work, can someone help me?

    Thank you

    $(document).ready(function() { $('#TableRecords').DataTable( {
    "language": {
    "lengthMenu": "Despliega MENU registros por pagina",
    "zeroRecords": "Ningun registro fue encontrado",
    "info": "Mostrando pagina PAGE de PAGES",
    "infoEmpty": "Ningun Registro Disponible",
    "infoFiltered": "(Filtrado de MAX registros totales)",
    "loadingRecords": "Cargando...",
    "processing": "Procesando...",
    "search": "Busqueda:",
    "paginate": {
    "first": "Primero",
    "last": "Ultimo",
    "next": "Siguiente",
    "previous": "Anterior"
    },
    "columnDefs": [
    {
    "targets": [ 1 ],
    "visible": false,
    "searchable": false
    },
    {
    "targets": [ 2 ],
    "visible": false
    }
    ]
    }
    } );

    } );

  • jLinuxjLinux Posts: 981Questions: 73Answers: 75

    If you apply the proper syntax highlighting for your code, I can try and help... The instructions for them are right below the Reply/Comment input text area...

  • kotushakotusha Posts: 3Questions: 1Answers: 0

    This is what does not work

    $(document).ready(function() { 
           $('#TableRecords').DataTable( { 
                   "language": { 
                                  "lengthMenu": "Despliega MENU registros por pagina", 
                                  "zeroRecords": "Ningun registro fue encontrado", 
                                  "info": "Mostrando pagina PAGE de PAGES", 
                                  "infoEmpty": "Ningun Registro Disponible",
                                  "infoFiltered": "(Filtrado de MAX registros totales)", 
                                  "loadingRecords": "Cargando...", 
                                  "processing": "Procesando...", 
                                  "search": "Busqueda:", 
                                  "paginate": { 
                                               "first": "Primero",
                                               "last": "Ultimo", 
                                               "next": "Siguiente", 
                                             "previous": "Anterior"
                                                     }
                                      }, 
                    "columnDefs": [ 
                                    {  
                                    "targets": [ 1 ], 
                                    "visible": false, 
                                   "searchable": false 
                                     }, 
                                    { 
                                    "targets": [ 2 ], 
                                    "visible": false 
                                    }
                              ]
                     
                });
    
    } );
    

    I also want to add this, all in the same script if possible:

    $(document).ready(function() { 
                  var table = $('#TableRecords').DataTable(); 
                  $('#TableRecords tbody').on('click', 'tr', function () { 
                             var data = table.row( this ).data();      
                            document.getElementsByName("OriDes_ID")[0].value = data[0];       
                            document.getElementsByName("OriDes_Ciudad")[0].value = data[2]; 
                      } );
     } );
    
This discussion has been closed.