getting undefined value on retriving values

getting undefined value on retriving values

AslamdotAslamdot Posts: 1Questions: 1Answers: 0
edited April 18 in Free community support
    <button id="button">btn</button>
    <table id="example" class="display" cellspacing="0" width="100%">
        <thead>
            <tr>
                <th>City</th>
                <th>Descption</th>
                <th>Devicename</th>

            </tr>
        </thead>


    </table>




                $(document).ready(function () {
                      table = $('#example').DataTable({
                    ajax: {
                 url: 'https://api.fda.gov/device/510k.json?search=product_code:NBW&limit=100',
                      dataSrc: 'results',
                      cache: true,
                    },
                    columns: [
                      {data: 'city'},
                      {data: 'advisory_committee_description'},
                      {data: 'device_name'}
                    ],
                    select: true,

                  });

                    $('#example tbody').on('click', 'tr', function () {
                        $(this).toggleClass('selected');
                    });

                    $('#button').click(function () {
                        var ids = $.map(table.rows('.selected').data(), function (item) {
                            return item[0]
                        });
                        console.log(ids)
                        alert(table.rows('.selected').data()[0][0] + ' row(s) selected');
                    });
                });

on click of a buttton on alert i should value of city but i am getting undefined value can some check on this?

Answers

  • kthorngrenkthorngren Posts: 21,443Questions: 26Answers: 4,974

    You have object based data using columns.data. When accessing the data use object notation in stead of array notation. For example return item[0] should be return item.city.

    Kevin

Sign In or Register to comment.