0
Good morning guys,
I’m using Datatable to sort, but when I change the value locally of the status and without posting on the page Datatable seems to ignore my change and sort all the others but what I just changed is not ordered, as if I had never changed the value of that field.
Follow the code below:
Jquery:
function IntanciaGrid() {
$('#gridTable').DataTable({
"aoColumnDefs": [
{
'bSortable': false,
'aTargets': [3]
}
],
"language": {
"paginate": {
"next": "Próximo",
"previous": "Anterior"
},
"emptyTable": "Não foi possível encontrar nenhum registro!"
},
});
}
This is the status change button:
<button class="btn @(item.Ativo == 0 ? "btn-success" : "btn-danger") btn-xs btnAlteraStatus" type="button" data-id="@item.IdCurso">
<i class="fa @(item.Ativo == 0 ? "fa-plus-circle" : "fa-minus-circle")"></i>
</button>
Grid:
<table class="table table-bordered table-hover" id="gridTable">
<thead style="background-color:#B2DFEE;">
<tr>
<th class="stf-aligntext" style="width:60%"><b>Cursos Técnicos e/ou FIC</b></th>
<th class="stf-aligntext" style="width:15%"><b>Tipo</b></th>
<th class="stf-aligntext" style="width:15%"><b>Status</b></th>
<th class="stf-aligntext" style="width:10%"><b>Ações</b></th>
</tr>
</thead>
<tbody>
@foreach (PronatecDados.DALC.Entities.Curso item in Model)
{
<tr>
<td class="stf-aligntext">@item.NomeCurso</td>
<td class="stf-aligntext">@(item.Tipo == 1 ? "Fic" : "Técnico")</td>
<td class="stf-aligntext">@(item.Ativo == 1 ? "Ativo" : "Inativo")</td>
<td class="stf-aligntext">
<a href="@Url.Action("Cadastrar", "CursoProfissionalizante", new {id = @item.IdCurso })" class="btn btn-primary btn-xs">
<i class="fa fa-pencil"></i>
</a>
<button class="btn @(item.Ativo == 0 ? "btn-success" : "btn-danger") btn-xs btnAlteraStatus" type="button" data-id="@item.IdCurso">
<i class="fa @(item.Ativo == 0 ? "fa-plus-circle" : "fa-minus-circle")"></i>
</button>
</td>
</tr>
}
</tbody>
</table>
I found an example of what I’m trying to do:
Already tried to re-load it after value change?
– Danilo Pádua
Reload na Grid?
– AleBabaloff
Yes. Na Datatables. https://datatables.net/reference/api/ajax.reload()
– Danilo Pádua
Can you show me how to insert this method?
– AleBabaloff
How’s your grid code?
– Danilo Pádua
@Danilo, sorry, had not put the code grid, now put.
– AleBabaloff