1
I am feeding my table by ajax and customizing the return.
In the column status
( 0 or 1 ) I used the "fnRender"
to return a label of active or inactive according to the value, but I need to use this same validation to show the button Deactivate or Activate and when I get to this step "fnRender"
overwritten the actual value of status
for "<span class='label label-success'>Ativo</span>"
( or Inactive ) and my validation for "mData":"id"
that is if(parseInt(oObj.aData['status']) == 1)
It always ends up in Isis.
Possible solution
if(oObj.aData['status'] == "<span class='label label-success'>Ativo</span>")
The problem is that I didn’t want to perform this validation by string, it seems somehow that this isn’t right.
Javascript:
var tabela = $('#dynamic-table');
tabela.dataTable( {
"aaSorting": [[ 0, "asc" ]],
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "minhaURL",
"aoColumns": [{
"mData":"nome"
},
{
"mData":"status",
"bSortable": false,
"fnRender": function (oObj)
{
var status;
if(parseInt(oObj.aData['status']) == 1){
status = "<span class='label label-success'>Ativo</span>";
}else{
status = "<span class='label label-danger'>Inativo</span>";
}
return status;
}
},
{
"mData":"id",
"bSearchable": false,
"bSortable": false,
"fnRender": function (oObj)
{
var btAtivaDesativa;
btEditar = "<a href='" + oObj.aData['id'] + "' class='btn btn-primary'>Editar</a>";
if(parseInt(oObj.aData['status']) == 1){
btAtivaDesativa = "<a href='" + oObj.aData['id'] + "' class='btn btn-danger'>Desativar</a>";
}else{
btAtivaDesativa = "<a href='" + oObj.aData['id'] + "' class='btn btn-success'>Ativar</a>";
}
return btEditar + " " + btAtivaDesativa;
}
}
]
} );
explains right Ale! rss kkkk
– andrepaulo