i have an issue with cell().data()

i have an issue with cell().data()

varshnagevarshnage Posts: 2Questions: 0Answers: 0
var table = $("#productlist tr.selected td:nth-last-child(2)").DataTable();
        $('#partTermSearch tbody').on('click', 'button', function () {
            var currow = $(this).closest('tr');

                var ptID = currow.find('td:eq(1)').text();
                var ptName = currow.find('td:eq(4)').text();

                var result = ptID + ' - ' + ptName;
               table.cell().data(result).draw();

                var row = {
                    partTermID: ptID,
                    partTermName: ptName,
                    flag: 1
                };

                UpdateRowData(row);
        });

i get the error on line table.cell().data(result).draw();
the error is - Unhandled exception at line 130, column 358 in https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js

0x800a138f - JavaScript runtime error: Unable to get property '0' of undefined or null reference

how do i resolve this problem?

Replies

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947

    You probably need to provide a cell-selector as noted in the cell() documentation. Maybe something like this:

    table.cell( $(this) ).data(result).draw();

    Kevin

  • varshnagevarshnage Posts: 2Questions: 0Answers: 0
    edited September 2018

    Thanks for reply @ Kevin

    Still it gives same runtime error
    Is there any need to add additional library for cell().data

  • allanallan Posts: 63,455Questions: 1Answers: 10,465 Site admin

    No - its built into DataTables core.

    What selector did you use? table.cell() isn't actually selecting any cell, like Kevin said.

    If you link to a page showing the issue I can take a look at it.

    Allan

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947

    Sorry, didn't notice it before but I suspect the selector in this line is not returning a Datatables API instance:
    var table = $("#productlist tr.selected td:nth-last-child(2)").DataTable();

    Try changing it to this:
    var table = $("#productlist").DataTable();

    Kevin

This discussion has been closed.