I'm using Django framework for my web site but to show info I use the plugin Datatable so one column show date info, the format that is used to show the date is like May. 6, 2017 so when I sort the date column take the order as string and not date so the first date to show is like August 10, 2017 Is there a way to sort by date using that format?
            Asked
            
        
        
            Active
            
        
            Viewed 991 times
        
    1
            
            
        
        M. Gar
        
- 889
 - 4
 - 16
 - 33
 
- 
                    1Show some code where you need this. How you are using datatable. It will be really hard to understand without any code that what exactly is your requirement – Arpit Solanki Aug 21 '17 at 15:24
 - 
                    You could use the data-order tag in that column. – Jingo Aug 21 '17 at 16:15
 - 
                    This is an example @ArpitSolanki https://jsfiddle.net/dunhxf5m/ – M. Gar Aug 21 '17 at 19:06
 
1 Answers
1
            
            
        When defining the columns of your DataTable, you need to specify the render callback as in the example below:
        columns: [
            {
                title: "Date",
                data: "yourDateRef",
                render: function(data, type, row) {
                    if (type == "display") {
                        return prettyFormat(data);
                    }
                    else {
                        return data;
                    }
                }
            },
            ...
Basically, DataTables calls the render callback to display the data (type=="display"), but also when the data needs to be sorted (type=="sort"), or filtered (type=="filter").
This allows you to control how a given field is displayed, but also sorted and filtered.
More information: https://datatables.net/reference/option/columns.render
Hope this helps!
        Bertrand Martin
        
- 533
 - 1
 - 3
 - 16