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

92
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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