Pls. Help me! How can i get data from ID column which is visible = false

Pls. Help me! How can i get data from ID column which is visible = false

justinbee112justinbee112 Posts: 1Questions: 0Answers: 0
edited September 2013 in General
Hi all. I don't know how to get ID from colume which is visible = false

Here my code:

var oTable;
$(document).ready(function () {
clickOnRow();
/* Init the table */
oTable = $('#example').dataTable({
"bProcessing": true,
"sAjaxSource": "Act/LoadListCarrier",
"aoColumns": [
{ "mData": "ID" },
{ "mData": "CarrierName" },
{ "mData": "DateCreate" },
{ "mData": "DateUpdate" }
],
"aoColumnDefs": [
{ "bSearchable": false, "bVisible": false, "aTargets": [0] },
],
'fnInitComplete': function () {
clickOnRow();
}
});

$("#btn_Delete").click(function () {
var selected = fnGetSelected(oTable);
oTable.fnDeleteRow(selected[0]);
$.ajax({
type: "POST",
async: false,
url: "Act/DeleteCarrier",
data: { CarrierID: $(selected).text() },
success: function (result) {
alert("worked!");
}
});
});

function fnGetSelected(oTableLocal) {
var aReturn = new Array();
oTableLocal.$("tr").filter(".row_selected").each(function (index, row) {
//aReturn.push(row); // this should work, if not try aReturn.push($(row));
//to get the information in the first column
aReturn.push($(row).eq(0).text());
});
return aReturn;
}

});

function clickOnRow() {
$('#example tbody tr').click(function (e) {
if ($(this).hasClass('row_selected')) {
$(this).removeClass('row_selected');
}
else {
$('#example tbody tr.row_selected').removeClass('row_selected');
$(this).addClass('row_selected');
}
});
}

I want to get ID from tr to post it. But in fnGetSelected i can't find the ID colume Pls help me.
Thanks

Replies

  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    edited September 2013
    You can get the data from datatables via api call

    http://datatables.net/api#fnGetData

    pass in the TR if you already have it, and get back an array of data that represents that row (even hidden columns)

    if you know which position the data is in (column 0) you can pass that in as param 2 and just get back that single value.
This discussion has been closed.