Datatable does not sort the field when you change the value locally

0

Good morning guys,

I'm using the Datatable to do sorting, however when I change the value locally from the status and without posting the page the Datatable seems to ignore my change and sorts all others but what I just changed is not sorted, 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 button that changes the status:

<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>&nbsp;
                                <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:

Research the Tokyo Field:

OverridevalueinHTMLonly:

Hedoesnotorder,Ineedyoutoorder...

    
asked by anonymous 30.11.2015 / 13:00

1 answer

-1

Place "ordering": true in function InstanciaGrid() :

function IntanciaGrid() {

    $('#gridTable').DataTable({
        "aoColumnDefs": [
            {
                'bSortable': false,
                'aTargets': [3]
            }
        ],
        //Inclua o ordering
        "ordering": true,
        "language": {
            "paginate": {
                "next": "Próximo",
                "previous": "Anterior"
            },
            "emptyTable": "Não foi possível encontrar nenhum registro!"
        },
    });
}
    
30.11.2015 / 17:00