Skip to content Skip to sidebar Skip to footer

How To Get Current Table Id To Add To Ajax Data When Initialisation Is Used For Multiple Tables?

I have the following initialisation for multiple tables with the same class but different id attributes: var $table = $('table.jobs'); $table.DataTable({ .... ajax: {

Solution 1:

You can try something like this:

$('.table.jobs').each(function () {
    $('#'+$(this).attr('id')).dataTable({
         url: '/my-url',
    dataSrc: function (json) {

        return json.data
    },
    data: function(data) {

        data.table_id = $table.attr('id');
        // gives the same id for all tables

    }
});

Post a Comment for "How To Get Current Table Id To Add To Ajax Data When Initialisation Is Used For Multiple Tables?"