Sort component DataTables by Date

1

I'm using the DataTables compiler where it returns the birthdays for the month. I am ordering on my controller by day, and it works correctly on a regular table. Is there a way to change the dataTable to sort as it receives the controller data?

Follow my controller:

 public ActionResult Aniversariantes()
    {

        var usuarios = usuarioRepository.Lista.Where(u => u.DtNascimento.Month == DateTime.Now.Month);
        var usuariosOrdenados = usuarios.OrderBy(u => u.DtNascimento.Day).ToList();
        return View(usuariosOrdenados);

    }

My View:

@model IEnumerable<PortalRH.DomainModel.Entities.Usuario>


@{
ViewBag.Title = "Aniversariantes do Mes";
}

<div class="row">
<div class="col-md-2">

</div>
<div class="col-md-8">
    <div class="panel panel-default">
        <div class="panel-heading">
            <h5><strong>Aniversariantes do Mes</strong></h5>
        </div>
        <table id="myTable" class="table">
            <thead>
                <tr>
                    <th>Nome do Funcionário</th>
                    <th>Secretaria</th>
                    <th>Data do Aniversário</th>
                </tr>
            </thead>
            <tbody>
                @foreach (var item in Model)
                {
                    <tr>
                        <td>
                            @item.NmFuncionario
                        </td>
                        <td>
                            @item.Descricao
                        </td>
                        <td>
                            @item.DtNascimento.Day.ToString("00")/ @item.DtNascimento.Month.ToString("00")
                        </td>
                    </tr>
                }
            </tbody>
        </table>

    </div>
</div>

<script>
var $j = jQuery.noConflict();
$j(document).ready(function () {
    $j("#myTable").dataTable();
});
</script>
    
asked by anonymous 23.01.2015 / 12:48

1 answer

1

I was able to add the field and sort order in my script.

<script>
var $j = jQuery.noConflict();
$j(document).ready(function () {
    $j("#myTable").dataTable({
        "aaSorting": [[2, "asc"]]
    });
});

    
23.01.2015 / 13:02