jquery - How do get data of a row DataTables? -
i started datatable https://www.datatables.net/. use lasted datatable.i can load data json string via ajax datatable.and want data when click in row .as see datatable debugger @ http://debug.datatables.net/idihol page test.aspx
<table id="div_table" class="display cell-border compact" width="100%"> <thead> <tr> <td>no</td> <td>name</td> <td>des</td> <td>lid</td> <td>aid</td> <td>date</td> <td>by</td> </tr> </thead> </table>
and script
var table = $('#div_table').datatable({ "processing": false, "serverside": false, "ajax": { "url": "../bus/webservice.asmx/list_location", datasrc: function (json) { return $.parsejson(json.d); }, "datatype": "json", "contenttype": "application/json; charset=utf-8", "type": "post" }, "aocolumns": [ //// 7 columns datatable { "mdata": null, "atargets": [0], "stype": "integer", "bsearchable": false, "orderable": false }, { "mdata": "location_name", "atargets": [1], "stype": "string" }, { "mdata": "location_des", "atargets": [2], "stype": "string" }, { "mdata": "location_id", "atargets": [3], "stype": "string", "bvisible": false, "bsearchable": false, "orderable": false }, { "mdata": "area_id", "atargets": [4], "stype": "string", "bvisible": false, "bsearchable": false, "orderable": false }, { "mdata": "edit_date", "atargets": [5], "stype": "date", "bvisible": false, "bsearchable": false, "orderable": false }, { "mdata": "edit_by", "atargets": [6], "stype": "string", "bvisible": false, "bsearchable": false, "orderable": false } ], "order": [[1, 'asc']] }); //table.columns([3, 4, 5, 6]).visible(false); //// disable column 4,5,6,7 //// create index column 1 table.on('order.dt search.dt', function () { table.column(0, { search: 'applied', order: 'applied' }).nodes().each(function (cell, i) { cell.innerhtml = + 1; }); }).draw(); $('#div_table tbody').on('click', 'tr', function () { // full data or columns @ row selected $(this).toggleclass('selected'); var data_ = table.row($(this)).data(); alert(data_[3] + " , " + data_[4]); /// alert(table.row($(this)).data()); error show info "object object" });
after run , error "undefined , undefined" can tell me problem , give me advice .thank.
the problem json data array of objects properties location_name
, location_des
you're trying retrieve data using indexes (data_[3]
, data_[3]
) if json data array of arrays.
from row().data() manual page:
function returns: data source object data source of row. array if use dom sourced data, otherwise array / object / instance used populate table data.
the data you're trying retrieve available in data_['location_id']
, data_['area_id']
.