How to get current table id to add to ajax data when initialisation is used for multiple tables?

How to get current table id to add to ajax data when initialisation is used for multiple tables?

martincarlin87martincarlin87 Posts: 13Questions: 4Answers: 1
edited September 2017 in Free community support

I have the following initialisation for multiple tables with the same class but different id attributes:

var $table = $('table.jobs');

$table.DataTable({

    ....
    ajax: {
        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

        }
    },
    ...
});

Is there a way I can identify which table is sending the ajax request?

Answers

  • martincarlin87martincarlin87 Posts: 13Questions: 4Answers: 1

    Managed to get it:

    var $tables = $('table.jobs');
    
     $tables.each(function () {
    
            var $table = $(this);
    
            $table.DataTable({... });
    });
    
This discussion has been closed.