Home » Jquery » html – jQuery data-table Date not sorting for Different cultures

html – jQuery data-table Date not sorting for Different cultures

Posted by: admin February 22, 2020 Leave a comment

Questions:

I have a jquery data table that shows dates based on client culture .
my data table code is as follows

        $('#LeaseHistory').DataTable({

            paging: true,
            searching: true,
            "aaSorting": [],
            "order": [],                
             columnDefs: [
                {
                    targets: 3,
                    "type": 'datetime',
                    render: function (value) {
                        debugger;
                        if ('@clientCulture' != 'it-IT') {

                            if ((value == null || value == "" || value == undefined)) {
                                return "";
                            }
                            else if ('@dateFormat.ToUpper()' == 'DD/MM/YY') {
                                return value;
                            }
                            else {
                                console.log(value);
                                console.log(window.moment(value).format('@dateFormat.ToUpper()'));
                                return window.moment(value).format('@dateFormat.ToUpper()');
                            }

                        }
                        else {
                            return value;
                        }

                    }
                },

i cant seem to understand why dates are sorting wrongly can anyone help me fix this issue

How to&Answer: