JavaScript + Jquery DataTable – pass data to defaultContent json column

I have a dynamic jQuery data table. For the final column, I have the option of deleting rows. In order for this to execute, I need to pass the itemId value to the function specified within the button onClick attribute.

This is how I have currently done it but no luck:

defaultContent: "<button class='btn btn-danger' onclick='StockSearchManagment.DeleteStock(" + data.itemId + ")'>Delete</button>"

This is my full JavaScript function:

 GetInfo: function (tble) {
$(document).ready(function () {
    $.ajax({
        url: '/Home/GetList',
        dataType: "json",
        method: 'post',
        success: function (data) {
            tble.DataTable().destroy();
            tble.DataTable({
                data: data.html
                ,
                "columns": [
                    { data: "itemId" },
                    { data: "name" },
                    { data: "description" },
                    {
                        data: null,
                        defaultContent: "<button class='btn btn-danger' onclick='StockSearchManagment.DeleteStock(" + data.ItemId + ")'>Delete</button>"
                    }
                ]
            });
        },
        error: function (err) {
            alert(err);
        }
    });
});

}

Answer

I refered to this stack overflow question: Passing more than one value into a button in the server side Datatable Jquery using MVC

It’s now working with render instead of defaultContext:

"render": function (data, type, full) {

 return '<button class="btn btn-danger" onclick="StockSearchManagment.DeleteStock(' + full.itemId + ')">Delete</button>';

}