Samjus
Samjus

Reputation: 675

Why is my Date sorting alphabetical instead of newest to oldest. Jquery DataTables

I have a datatable and my date is sorted at the beginning from newest to oldest. When I click on the sort tab it is sorting it by alphabet. How could I go about sorting it from newest to oldest when I click the sort. I've tried aoColumns and asSorting and ao ColumnDefs and I am stumped.

I sort my date by descending in my controller.

var coupons = couponRepository.GetList(c => c.TenantId == tenant.ID).OrderByDescending(c => c.RedemptionDate);

My initialization code:

$(document).ready(function () {
        //Grid
        $(".gridView").dataTable({
         "bJQueryUI": true,
         "sPaginationType": "full_numbers",
         "aoColumnDefs": [
               { "asSorting": ["desc", "asc"], "aTargets": [4] }
         ]
});
});

Thanks :)

Upvotes: 0

Views: 972

Answers (1)

Buildstarted
Buildstarted

Reputation: 26689

Based on your code I assume you're using the code located at http://datatables.net if that's the case I suggest you check out the plugins listed http://www.datatables.net/plug-ins/sorting There's a plugin to allow for sorting by dates.

Upvotes: 1

Related Questions