row data with 2 datatables on a page doesn't return id column

row data with 2 datatables on a page doesn't return id column

az1az1 Posts: 14Questions: 7Answers: 1

Hi there

When I add 2 datatables to a page and look at the row data when selecting a row, the Id column is not returned in the row data - I'm assuming that there must be a conflict between the 2 datatables.
Is there somewhere else I need to make the tables unique apart from the main table id?

$('#@Model.DataTable.ControlId tbody').on('click', 'tr', function () {

var table = $('#@Model.DataTable.ControlId').DataTable();
var temp = table.row(0).data();
console.log(temp)

});

I have added a screenshot where the page on the left has just one datatable and the table on the right has 2 datatables and the id is not being logged out to the console when the row is being clicked on.

Answers

  • kthorngrenkthorngren Posts: 20,150Questions: 26Answers: 4,736

    It looks like the table on the left is using object based data while the table on the right is using array based data. My guess is the JSON data returned for the left table has an Id object. The place to start is to look at the response data for each and maybe use object based data for the table on the right.

    More info about data structures here:
    https://datatables.net/manual/data/#Data-source-types

    If this doesn't help then we will need to see examples in order to help troubleshoot. Please post a link to your page or a test case replicating the issue.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • az1az1 Posts: 14Questions: 7Answers: 1

    Hi Kevin

    The table on the right is actually the same table as the one on the left!
    All I have done is add a second table below it and then the structure of the top one changes and it loses the id!
    The id is definitely in the datasource.
    Is there anything else I need to do when 2 tables are on the same page and I want the rowdata (id) on click of the table?

    Do you have an example of this working?

    Any help will be appreciated.

    thanks
    Az

  • kthorngrenkthorngren Posts: 20,150Questions: 26Answers: 4,736

    Here is an example of two Datatables on the same page.
    https://datatables.net/examples/basic_init/multiple_tables.html

    The data structures you are showing is different for the two tables. The screenshots are not enough for us to help. Please post a link to your page or a test case replicating the issue. This will allow us to see what is happening so we can offer assistance.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

This discussion has been closed.