Search code examples
htmljquerydatatables

How do I get my data.id of each row with using return in jquery please?


I have a table that displays the elements retrieved from an API in Jquery I would like to retrieve the IDs of the rows to add a deletion or a modification

$("#examplee").DataTable({

    "data" : data,
    "columns":[
        {"data" : 'numeroDossier'},
        {"data" : 'nomOuRs'},
        {"data" : 'tel'},
        {"data" : 'province'},
    
        {
            data : null,
            render : function()
            {
            
                return '<a><i class="btn fa-solid success fa-user-tag" onclick="get_assaj(\''+data.id+'\')" title ="selectionner assujetti" ></i></a><a><i class="btn fa fa-solid fa-user-pen" style="color: #B197FC" onclick="edit_assaj('+ data +')" ></i></a>';
    
                                        

            }
            
            
        }


    ]

})

Solution

  • You can use the row parameter of the render function to access row-specific information:

    render: function (data, type, row) {
      const id = row.id;
    
      ...
    }
    

    For more details you can check documentation.