Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

161
Vistas
Datatable pagination and jquery done function

The following code creates a datatable with the data that identifies users and the companies they have worked for.

for (var number = 0; number < users.length; number++) {
    var one_row = new Array();
    one_row.push("<br>" + userData);
    rows_builder.push(one_row);

    getUserCompaniesNames(id, number);
}


function getUserCompaniesNames(id, number) {
    getUserCompanies(id).done(function(userCompanies) {

        var result = JSON.parse(userCompanies);
        if (result != null) {
            var text = "";
            for (var i = 0; i < result.length; i++) {
                text += "<u>" + result[i].name_company + "</u>";   
            }
            $('.myclass' + number).append(text);
        }
    }).fail(function(err) {
        console.log(err);
    });
}

It works fine except for this: when I use pagination and go from the first page of 10 results to the next, I lose the information generated by the getUserCompaniesNames function.

I think the problem is here:

$('.myclass' + number).append(text); 

And the only thing I can think of is to create a global array and add just below:

$('.myclass' + number).append(text); 

This:

myGlobalArray.push(text); // declared var myGlobalArray = new Array(); in the first line of my code

But when I check myGlobalArray outside the function, it comes up empty. I understand that the function is taking more time to execute but I don't know how to fix all this and have the information from getUserCompaniesNames in the datatable when using pagination.

Thanks in advance!

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda