Load Datatables in a table loaded dynamically with Jquery?

1

I have a table in a html page that I post in another html with jquery load();

When charged dynamically the sun does not recognize it and I can not load the table.

$(function() {
       $('#contenedor-home').load('Views/Vista1.php');//Vista1 contiene la tabla

tabla = $('#example').DataTable( {
        "language": {
            "url": "js/lib/spanis-datatables.json"
        },
        "ajax": {
            "url": "Services/getAllUsuarios.php",
            "dataSrc": ""
        },
        "columns": [
            { "data": "id" },
            { "data": "nombre" },
            { "data": "password" },
            { "data":"id",
                "render": function(data){
                    return '<a class="delete" onclick="eliminarUsuario('+data+')"><i class="fa fa-fw fa-trash-o btn-lg"></i></a><a class="edit" onclick="editarUsuario('+data+')"><i class="fa fa-fw fa-pencil btn-lg"></i></a>';
                }}
        ]
    } );
}
    
asked by Rodrigo Benito 10.01.2017 в 13:03
source

1 answer

0

As @Cesar moro says in the comments, it may be a problem with asynchronous calls.

Try to do the following:

$('#contenedor-home').load('Views/Vista1.php', function(){
   // acá pones el código configura tu Datatable
});

This allows the table's fill code to be executed right after the HTML of Vista1.php has been loaded correctly

    
answered by 10.01.2017 / 14:51
source