How to get a cell from a selected row in DataTables

How to get a cell from a selected row in DataTables

Jevison7xJevison7x Posts: 1Questions: 1Answers: 0
edited April 2016 in Free community support

I have a table as follows:

var custTable = $("#customer-records-table").DataTable({
        "paging": false,
        "info": true,
        "scrollY": 300,
        columnDefs: [
            {
                type: 'currency',
                targets: [5, 6]
            }
        ],
        /* Disable initial sort */
        "aaSorting": []
    });

Then I can get a row by using the id to select it:

var row = custTable.row('#customer-' + customerObj.customerId);

I still can't understand how to get the first, second and third cells/columns from the row,
and I will like to be able to update some of the cells. Thanks.

Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,787Questions: 1Answers: 10,511 Site admin
    Answer ✓

    Use the cell() or cells() selectors to get the cells. For example:

    var data = custTable.row('#customer-' + customerObj.customerId, 0).data();
    

    will give you the data for the row matching the row selector given in column index 0.

    cell().data() can also be used as a setter to set values.

    Allan

This discussion has been closed.