Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

163
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda