Sorting Datatable column by a field of type Datetime

Asked

Viewed 285 times

0

I have the following field in my model:

[Required]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime? DataCadastro { get; set; }

I use Displayformat to format and display the date in Brazilian format later in a Datatable. But it’s not being sorted correctly. I need to put something else in the datatable ?

$('#table-controle').html(data);
dataTable = $('#table-controle').dataTable({
    "language": {
        "url": "../../../Content/json/Portuguese-Brasil.json"
    }
});
  • You can put your code here on Jsfidlle?

  • Raphael, a piece of advice, unless you’re doing something trivial, like a popular textbox, avoid formatting server-side values, blibiotecas like datatables work best with json suffering the least amount of possible inteference. in your case, I believe it is best to use the following datatables plugin datetime together with the columns.type date

  • I found the solution in this post: http://stackoverflow.com/questions/12124746/disable-automatic-sorting-on-the-first-column-when-using-jquery-datatables

No answers

Browser other questions tagged

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