最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Cannot read property '_aData' of undefined(…) - Datatables - Stack Overflow

programmeradmin2浏览0评论

I'm trying to read data() from a cell in a datatable which has a button inside it, but I'm getting en error.

This is my Datatable definition:

$("#example").DataTable({
                destroy: true,
                "columnDefs": [{
                    orderable: false,
                    targets: 0
                }],
                "columns": [
                    {
                        "data": "slno",
                        "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
                            $(nTd).html('<a href="AddNewTicket.aspx?subjectID=' + oData.subjectID + '&subject_id=' + oData.subject_id + '&serviceID=' + oData.crm_services_id + '&severityID=' + oData.severityID + '&statusID=' + oData.statusID + '&callerID=' + '66355356' + '">' + oData.slno + '</a>');
                        },
                    },
                    { "data": "status_message" },
                    { "data": "crm_services_id" },
                    { "data": "subject_id" },
                    { "data": "severity_id" },
                    {"data": "user_id" },
                    { "data": "status_id" },
                    {
                        "data": "caller_number",
                        "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
                            $(nTd).html('<button class="btn btn-primary" id= "' + oData.subjectID + '">Call Customer</button>');
                        },
                    }
                ],
                select: {
                    style: 'os',
                    selector: 'td:first-child'
                },
                "data": response,
                "sDom": '<"top">tip'
            });

And here is where I'm trying to fetch the data:

var table = $("#example").DataTable();
        $('#example tbody').on('click', 'button', function () {
            var subjectID = $(this).attr('id');
            var thisData = table.row($(this).parents('tr')).data();
            var userID = thisData[7];
            sendCallRequest(subjectID, userID);
        });

Here is the error I'm getting:

Cannot read property '_aData' of undefined(…)

Any suggestions please?

I'm trying to read data() from a cell in a datatable which has a button inside it, but I'm getting en error.

This is my Datatable definition:

$("#example").DataTable({
                destroy: true,
                "columnDefs": [{
                    orderable: false,
                    targets: 0
                }],
                "columns": [
                    {
                        "data": "slno",
                        "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
                            $(nTd).html('<a href="AddNewTicket.aspx?subjectID=' + oData.subjectID + '&subject_id=' + oData.subject_id + '&serviceID=' + oData.crm_services_id + '&severityID=' + oData.severityID + '&statusID=' + oData.statusID + '&callerID=' + '66355356' + '">' + oData.slno + '</a>');
                        },
                    },
                    { "data": "status_message" },
                    { "data": "crm_services_id" },
                    { "data": "subject_id" },
                    { "data": "severity_id" },
                    {"data": "user_id" },
                    { "data": "status_id" },
                    {
                        "data": "caller_number",
                        "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
                            $(nTd).html('<button class="btn btn-primary" id= "' + oData.subjectID + '">Call Customer</button>');
                        },
                    }
                ],
                select: {
                    style: 'os',
                    selector: 'td:first-child'
                },
                "data": response,
                "sDom": '<"top">tip'
            });

And here is where I'm trying to fetch the data:

var table = $("#example").DataTable();
        $('#example tbody').on('click', 'button', function () {
            var subjectID = $(this).attr('id');
            var thisData = table.row($(this).parents('tr')).data();
            var userID = thisData[7];
            sendCallRequest(subjectID, userID);
        });

Here is the error I'm getting:

Cannot read property '_aData' of undefined(…)

Any suggestions please?

Share Improve this question edited Nov 2, 2016 at 11:10 Gyrocode. 58.9k16 gold badges156 silver badges191 bronze badges asked Nov 1, 2016 at 9:33 Husain AlhamaliHusain Alhamali 8234 gold badges20 silver badges34 bronze badges 1
  • Hi, did you solved this? – NineCattoRules Commented Jan 25, 2017 at 23:49
Add a ment  | 

1 Answer 1

Reset to default 8

Try unbinding the event for your buttons before you re-assign them:

var table = $("#example").DataTable();

    $('#example tbody').off('click');

    $('#example tbody').on('click', 'button', function () {
        var subjectID = $(this).attr('id');
        var thisData = table.row($(this).parents('tr')).data();
        var userID = thisData[7];
        sendCallRequest(subjectID, userID);
    });

Why am I suggesting this: I have a pretty similar problem, where DataTables is not able to call the rowReorder event. I also create my table via AJAX / dynamically (which you seem to do aswell), so obviously my event listener (in my case for table.on('row-reorder')) was bound multiple times. After first removing the event listener and readding it, finally I got this to work.

发布评论

评论列表(0)

  1. 暂无评论