sVisible issue

sVisible issue

bogusbogus Posts: 16Questions: 0Answers: 0
edited December 2009 in General
I have a question:making a column bVisible:false hides that column or it isn't created any for that column?

I have this column definition
[code]
"aoColumns": [
{ "sTitle": "HeroId",
//"bVisible": false
},
{ "sTitle": "Name" },
{ "sTitle": "Level" },
{ "sTitle": "Race"},
{ "sTitle": "IsImba",
"fnRender": function(obj) {
var sReturn = obj.aData[obj.iDataColumn];
return (sReturn == "1")?"Imbaaa":"Not imba";
}
}],
[/code]
and a function that gets the selected row, gets the HeroId, post it to the server side where the deletion is performed and as a callback a refresh is done
[code]
function Delete_Click() {
var anSelected = fnGetSelected(oTable);
var heroId = $(anSelected).find("td").eq(0).html();
$.post('<%=Url.Action("Delete","Home")%>',
{ id: heroId },
function() {
oTable.fnReloadAjax('<%=Url.Action("GetData","Home")%>');
},
'josn');
}
[/code]

This works well, but if i want to hide the HeroId column, $(anSelected).find("td").eq(0).html() will point to the Name column, how can i access the HeroId column in this case?

Replies

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin
    Hi bogus,

    The TD might be created (depending on the code flow), but if it is hidden, then it certainly isn't added to the DOM (it might be removed, again depending on the code flow). So you can't just use standard DOM methods to access hidden TD elements, since they aren't there. What you can do is make use of fnGetData ( http://datatables.net/api#fnGetData ) to get the array of data that DataTables knows about.

    Regards,
    Allan
  • bogusbogus Posts: 16Questions: 0Answers: 0
    Thanks again Allan, i did something like this, i doubt it is the best approach so i'm waiting for your opinion
    [code]
    var oTable;
    var selected = new Array();
    var counter = 0;
    $("#example tbody").click(function(event) {
    var r = $(event.target.parentNode);
    var rIndex = r[0].rowIndex;
    if (r.hasClass('row_selected')) {
    r.removeClass('row_selected');
    selected = jQuery.grep(selected, function(value) {
    return value != rIndex;
    });
    counter--;
    }
    else {
    r.addClass('row_selected');
    selected[counter] = rIndex-1;
    counter++;
    }
    });
    function Delete_Click() {
    var idsToDelete = new Array();
    for (var x = 0; x < selected.length; x++) {
    idsToDelete.push(oTable.fnGetData(selected[x])[0]);
    }
    $.post('<%=Url.Action("Delete","Home")%>',
    { id: idsToDelete },
    function() {
    oTable.fnReloadAjax('<%=Url.Action("GetData","Home")%>');
    },
    'json');
    }
    [/code]

    Whenever a row is selected i add its index in an array and when it is deselected i remove its index from the array.
    When i want to do something with the selected rows i use the magic fnGetData to retrieve the rows corresponding to those indexes and then the column i'm interested in
  • bogusbogus Posts: 16Questions: 0Answers: 0
    Oh..there already is fnGetSelected() which can extract the indexes of the selected rows :) silly me..again
This discussion has been closed.