How to get data in a row DataTable ?

How to get data in a row DataTable ?

headshot9xheadshot9x Posts: 59Questions: 16Answers: 1

Hello guys . I started with DataTable , I can load data into DataTable via Ajax with JSON string, see Datatable debugger at http://debug.datatables.net/emacev, this is my page Test.aspx

<table id="example" class="display">
            <thead>
                <tr>
                    <td>No</td>
                    <th>LOCATION_ID</th>
                    <th>AREA_ID</th>
                    <th>LOCATION_NAME</th>
                    <th>DES</th>
                    <th>DATE</th>
                    <th>BY</th>
                    <th>FLAG</th>
                </tr>
            </thead>
        </table>

And this is my script

  var table;
            table = $('#example').DataTable({
                "processing": false,
                "serverSide": false,
                "ajax": {
                    "url": "../BUS/WebService.asmx/ListLocation",
                    dataSrc: function (json) {
                        return $.parseJSON(json.d);
                    },
                    "dataType": "json",
                    "contentType": "application/json; charset=utf-8",
                    "type": "POST"
                },               
                "aoColumns": [   /// eight columns set with columns of table
                    { "mData": null },
                    { "mData": "LOCATION_ID" },
                    { "mData": "AREA_ID" },
                    { "mData": "LOCATION_NAME" },
                    { "mData": "LOCATION_DES" },
                    { "mData": "EDIT_DATE" },
                    { "mData": "EDIT_BY" },
                    { "mData": "FLAG" }
                ],             
                "columnDefs": [{   // define  first column , is column zero 
                    "searchable": false,
                    "orderable": false,
                    "targets": 0
                }],              
                "order": [[3, 'asc']]   /// sort at column three
            });
            ////  create index for table at columns zero
            table.on('order.dt search.dt', function () {
                table.column(0, { search: 'applied', order: 'applied' }).nodes().each(function (cell, i) {
                    cell.innerHTML = i + 1;
                });
            }).draw();
            ////disable column 1,2,5,6,7
            table.column([1,2,5,6,7]).visible(false);
            //// Get data of row selected [data at column 1 and 2]
            $('#example tbody').on('click', 'tr', function () {
                $(this).toggleClass('selected');
                var data = table.row($(this)).data();
                alert(data[1] + "  " + data[2]);
            });

As you see,when i click a row in DataTable , it change color , but i can not get data in row . Please tell me and give me some advice. Thank, headshot

This discussion has been closed.