Multiple ajax source at Datatable

Multiple ajax source at Datatable

fikfatfikfat Posts: 1Questions: 1Answers: 0
edited October 2019 in Free community support

i have a question. can we put multiple ajax source at datatable and show it only to one table ? i have many link source like "https://link1.com/prices/?Origin=+Origin+&Destinaton=+Destinaton" and "https://link2.com/prices/?Origin=+Origin+&Destinaton=+Destinaton" . and i can only show data from 1 source .

var dataTable = $("#dtb_table").dataTable({
'bProcessing': true,
'bServerSide': false,
'sAjaxSource': "https://link1.com/prices/?Origin="+Origin+"&Destinaton="+Destinaton,
'columns': [
{ "data": "Moda" },
{ "data": "Service" },
{ "data": "Origin" },
{ "data": "Destinaton" },
{ "data": "Price" }
],
});

Answers

  • colincolin Posts: 15,144Questions: 1Answers: 2,586

    Hi @fikfat,

    I'm not sure whether you're saying you wish to merge the multiple sources or show them separately with a 'flick of a switch'.

    If merging, then it would be best to gather the data outside of DataTables. Use jQuery's ajax() function to get all the data, merge it together into a single object, and pass into DataTables's data.

    If you want to flip between multiple sources, you can change the URL with ajax.url().

    Cheers,

    Colin

  • momodiyermomodiyer Posts: 1Questions: 0Answers: 0

    Thank you for your suggestion, but in my case, as you said, the data has been separated, and an HTML file is used to load a JSON file with JS. But I want to make an integrated version that combines all the JSON files in one datatables for display. Just encounter this problem, do not know how to merge multiple together? Thank you?

  • colincolin Posts: 15,144Questions: 1Answers: 2,586

    If you want to do it in the browser, that second paragraph on my previous reply would be the way to go,

    Colin

This discussion has been closed.