How to sort by date instead of string with DataTable

DataTable perceives the date column as a default string and because it sorts alphabetically, illogical listing emerges. In order to avoid this problem, we need to add data-order to the column of the table and we need to combine the year month day hour minute second fields as a value.

<table>
    <thead>
        <tr>
            <th>Date</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td data-order="<%#Eval("DateColumn", "{0:yyyyMMddHHmmss}") %>"><%#Eval("DateColumn", "{0:dd.MM.yyyy HH:mm}") %></td>
        </tr>
    </tbody>
</table>

You may also like...