how to change the data displayed on the datatable from two different ajax data sources

how to change the data displayed on the datatable from two different ajax data sources

wirawanwirawan Posts: 1Questions: 1Answers: 0

I have multiple json data from two different data sources and have different keys, I want change with the change function on the selected option element. can datatable do this? The following code that I applied

$("#data-in").on('change', function () {
var get = ($(this).children("option:selected").text());
change(get)
});

function change(e) {
    var das = '';
    $.ajax({
        type: "GET",
        url: "url/" + e,
        dataType: "json",
        success: function (data) {

            if (e == 'global') {

                for (var i = 0; i < data.data.length; i++) {
                    var no = i + 1;

                    das += '<tr>' +
                        '<td>' + no + '</td>' +
                        '<td>' + data.data[i].attributes.Country_Region + '</td>' +
                        '<td>' + data.data[i].attributes.Active + '</td>' +
                        '<td>' + data.data[i].attributes.Recovered + '</td>' +
                        '<td>' + data.data[i].attributes.Deaths + '</td>' +
                        '</tr>'
                }

                $('tbody#data').html(das);
            }

            console.log(data);

        }
    });
}

The code above does work but doesn't work well. is there a better way

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    I'm not clear what you're after, but columns.render can be used to change the data.

    If that doesn't help, we're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

This discussion has been closed.