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

94
Views
elegir tabla de datos de URL ajax

quiero elegir datatable ajax url si contiene datos1, contiene datos2 o contiene datos3.

aquí está mi código:

 $(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' }, }

quiero hacerlo asi si se puede hacer

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

0

Si quiere decir que desea fusionar datos de muchas fuentes de datos, entonces sería mejor recopilar los datos fuera de DataTable. Use la función ajax() de jQuery (o cualquier cliente de JavaScript como axios) para obtener todos los datos, fusionarlos en un solo objeto y pasarlos a la opción de datos de DataTables.

Me gusta:

 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) }) }

luego, cuando defina su tabla de datos:

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

Nota: debe agregar async antes de la función lista porque estamos usando esperar antes de cada solicitud:

 $(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!