0

in this way I fetch the data

  $(document).ready(function() {
$('#example').DataTable( {

    "ajax": {
      "method":"POST",
      "url":"exampleurl.php"
      },
      "columns":[
          {"data":"title"},
          {"data":"description"},
          {"defaultContent": "<button  id='show-info' data-toggle='modal' data-target='#show-modal' class='btn btn-primary'>show</button>"}
      ]
} );

 $('#example tbody').on( 'click', 'button', function () {


  console.log( table.row( this ).data() );

      });
});

I have seen answers where they propose to use this

table.row( this ).data() 

but not work for me

1 Answer 1

2

Set a variable to the DataTable instantiation, and change table.row( this ).data() to table.row( $(this).parents('tr') ).data()

$(document).ready(function() {
    var table = $('#example').DataTable( {
        "ajax": {
            "method":"POST",
            "url":"exampleurl.php"
        },
        "columns":[
            {"data":"title"},
            {"data":"description"},
            {"defaultContent": "<button  id='show-info' data-toggle='modal' data-target='#show-modal' class='btn btn-primary'>show</button>"}
        ]
    } );

    $('#example tbody').on( 'click', 'button', function () {


        console.log(table.row( $(this).parents('tr') ).data());

    });
});
Sign up to request clarification or add additional context in comments.

2 Comments

tells me table is not defined
how did you fetch your data? @MichelNovellino

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.