Ajax help

Ajax help

Psycho3000Psycho3000 Posts: 4Questions: 1Answers: 0
edited April 24 in Free community support

Hey guys, Im new to DataTables and Ajax.

Here is a piece of my code:

$(document).ready( function () {
        var table = $("#table_id").DataTable({
    "ajax":  {
       
        "url": "liste/getTable",
        "dataSrc":""
    },
        "columns": [
            {"data": "**ID**"},
            {"data": "V"},
            {"data": "N"},
            {"data": "E"},
            {"data": "M"},
            {"data": "L"},
            {"data": "Mail"},
            {"defaultContent": '<a onclick="sendMail(**X**);"  class="btn btn-primary btn-sm" href="#"><span class="fa fa-envelope"></span></a>'}
            
        ]
    
});

setInterval( function () {
    table.ajax.reload();
});
      })

Everything is working but how can i put the ID from data: ID into the X in sendMail?

Sry for my bad english, i hope you can help me.

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 6,113Questions: 21Answers: 1,353

    You would need to use columns.render instead of columns.defaultContent. You would use the row parameter to get the ID for each row. The columns.render docs have examples that should help.

    Kevin

  • Psycho3000Psycho3000 Posts: 4Questions: 1Answers: 0
    edited April 24

    I understand that i need to use render. I still dont know how to get the ID. Maybe you could give me a hint :)

    i wrote this:
    "rowId": "ID",

    table.row( this ).id() did not get the ID though

    Thanks alot Kevin!

  • Psycho3000Psycho3000 Posts: 4Questions: 1Answers: 0

    table.row( this ).id() cant work i guess since i dont click anything... hmm

  • colincolin Posts: 5,631Questions: 0Answers: 983
    Answer ✓

    Hi @Psycho3000 ,

    The third argument to columns.render is the full data for the row - you can use this to get the value. See example here where the name is being placed into the column with the extension.

    Cheers,

    Colin

  • Psycho3000Psycho3000 Posts: 4Questions: 1Answers: 0

    Thanks a lot colin!!

Sign In or Register to comment.