I want to get the value of the invisible cell next to the one that the user selects

I want to get the value of the invisible cell next to the one that the user selects

MarkAinsworthMarkAinsworth Posts: 6Questions: 3Answers: 1

My code looks like this:

$(document).ready(function () {
$('#vendorList').DataTable({

            select: {
                style: 'os',
                items: 'cell'
            },
            ajax: {
                url: "vendors.php",
                dataSrc: ""
            },
            columns: [
                {data: "catalogManufacturer"},
                {data: "VendorNumber",
                visible: false}

            ]
        });

        //when vendor is selected, show items
        var vTable = $('#vendorList').DataTable();

        vTable.on( 'select', function (e, dt, type, indexes) {
            var idx = vTable.cell('.selected').index();

            var rowData = vTable.rows(idx.row).columns(idx.column).data();

                console.log(rowData);

        });
    });

The table is populated as expected. My json is just an array of associated arrays.

rowData appears to be the entire column at this point.

How do i get just the value for the colum

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,253Questions: 26Answers: 4,761
    Answer ✓

    rowData appears to be the entire column at this point.

    Basically rowData contains columns(idx.column).data() which will be all the data in that column. Using row() won't filter the data returned using column() even if chained like you have.

    How do i get just the value for the colum

    Use cell().data(). Maybe something like this:

    var VendorNumber = vTable.cell( idx.row, 1 ).data();
    

    Kevin

  • MarkAinsworthMarkAinsworth Posts: 6Questions: 3Answers: 1

    Simple enough. Thanks, Kevin for taking the time to answer.

This discussion has been closed.