Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

162
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!