Set Datatable column data type to date

Asked

Viewed 304 times

1

I have a Datatable that displays values coming from an SQL database, this way:

<table id="tabelaLogs">
    <thead>
        <tr>
            <th>Código</th>
            <th>
                Data
            </th>
            <th>
                Tipo
            </th>
            <th>
                Descricao
            </th>
            <th>
                Criador
            </th>
            <th>
                Computador
            </th>
        </tr>
    </thead>
    <tbody>
        @foreach (var item in Model)
        {
            <tr>
                <td>@Html.DisplayFor(modelItem => item.codigoLog)</td>
                <td>
                    @Html.DisplayFor(modelItem => item.dataHora)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.tipo)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.descricao)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.criadoPor)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.computador)
                </td>
            </tr>
        }
    </tbody>
</table>

As you can see column number 1 (Starting from 0), it is a column that displays a value coming from the BD that is a Date, in the format that the date is seen on my PC, in American format, MM/DD/YYYY HH:MM:SS A.

However, when it is passed to Datatable, the Date type is passed as String. If I run this command on the Chrome console: tableLogs.column(1). date[0], it returns this: "17/8/2017 21:35" . A String.

I wanted to return a Date variable, like this one: Thu Aug 17 2017 21:35:00 GMT-0300 (E. South America Standard Time)

So I can filter the table records that have the date, between two other.

I already started my Datatable with this codeword, but even so the column data type continues as String.

tabelaLogs = $("#tabelaLogs").DataTable({
                "columnDefs": [
                    { "sType": "date", "targets": 1 }
                ]
            });

Can someone help me?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.