Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Datables JS set cell value by row index and column index

I'm doing an AJAX request which returns an Id. The idea is to update my datatable without reloading the page. I get the row index perfectly. And set the row class perfectly. But now I want to set some values in some cells of that row. And I can't get it. It says 'table.cell is not a function'. Here's my code:

$.ajax({
    url: "trasladosDespacharGuardar.php",
    success: function(result) {
        id = parseInt(result);
        var index = table.fnFindCellRowIndexes( id, 1 );
        var row = table.api().row(index).node();
        $(row).addClass('warning');

        //Up to this point , everything is perfect
        var cell = table.cell(index,5);
        cell.data('Helloo');
    }
});
like image 410
martin.softpro Avatar asked Dec 03 '15 14:12

martin.softpro


1 Answers

In order to use cell the way as suggested in OP, use the { row, column } selector and finalize with draw() :

table.cell({ row: index, column: 5 }).data('Helloo').draw();

Regarding 'table.cell is not a function', the dataTable is probably not initialized with DataTable(), capital D. If there is a reason for initializing with dataTable() we still have access to the API by api() :

table.api().cell({ row: index, column: 5 }).data('Helloo').draw();
like image 55
davidkonrad Avatar answered Sep 19 '22 12:09

davidkonrad