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

89
Views
choosing ajax url datatable

i want to choose datatable ajax url whether its containingdata1 , containingdata2 or containingdata3 .

here is my code:

$(document).ready(function() {
var $table = $('#datatable1');
    $table.DataTable({
      "columnDefs": [
                     {"className": "dt-center", "targets": "_all"}
                    ],  
   if(containdata1){
   ajax: {
           url: "/api/dunapi/"+containdata1,
                type: 'GET'
            },

   if(containdata2){
    ajax: {  
        url  : "/api/dunapi/"+containdata2,
        type : 'GET'                      
            },
   
   }
   if(containdata3){
    ajax: {  
        url  : "/api/dunapi/"+containdata3,
        type : 'GET'                      
            },
   
   }

i want to do it like that if it can possibly be done

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If you mean that you want to merge data from many data source, then it would be best to gather the data outside of DataTable. Use jQuery's ajax() function (Or any JavaScript client like axios) to get all the data, merge it together into a single object, and pass into DataTables's data option.

Like:

var data = []

if(containdata1){
    await axios.get("/api/dunapi/"+containdata1).then(res => {
        data = data.concat(res.data)
    })
}
if(containdata2){
    await axios.get("/api/dunapi/"+containdata2).then(res => {
        data = data.concat(res.data)
    })
}
if(containdata3){
    await axios.get("/api/dunapi/"+containdata3).then(res => {
        data = data.concat(res.data)
    })
}

then when define your datatable:

{
// datatable options
data: data
.....
}

Note: you should add async before ready function because we are using await before each request:

$(document).ready(async function() {
......
}
about 4 years ago · Juan Pablo Isaza Report
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!