Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82358

Date sort(ascending-descending) in data Table according to month and day but not work for year

$
0
0

here I use date-eu.js for sorting but it doesn't work for sorting according to year,sorting work only for day and month

date-eu.js:

$.extend($.fn.dataTableExt.oSort, {

            "date-eu-asc": function (a, b) {
                console.log("inisde..js");
                if (a == '-') return 1;
                else if (b == '-') return -1;
                else {
                    var aDay = a.split('/')[0]
                    var aMonth = a.split('/')[1]
                    var aYear = a.split('/')[2]
                    var a = new Date(aMonth + "/" + aDay + "/" + aYear).getTime();

                    console.log("inisde..js a1"+a);

                    var bDay = b.split('/')[0]
                    var bMonth = b.split('/')[1]
                    var bYear = b.split('/')[2]
                    var b = new Date(bMonth + "/" + bDay + "/" + bYear).getTime();

                    console.log("inisde..js b1"+b);

                    return ((a < b) ? -1 : ((a > b) ? 1 : 0));
                }
            },

                "date-eu-desc": function (a, b) {
                if (a == '-') return 1;
                else if (b == '-') return -1;
                else {
                    var aDay = a.split('/')[0]
                    var aMonth = a.split('/')[1]
                    var aYear = a.split('/')[2]
                    var a = new Date(aMonth + "/" + aDay + "/" + aYear).getTime();

                    console.log("inisde..js a2"+a);

                    var bDay = b.split('/')[0]
                    var bMonth = b.split('/')[1]
                    var bYear = b.split('/')[2]
                    var b = new Date(bMonth + "/" + bDay + "/" + bYear).getTime();

                    console.log("inisde..js b2"+b);

                    return ((a < b) ? 1 : ((a > b) ? -1 : 0));
                }
            }
        });

I want solution that its sort for day/month and also for year.In photo you can see current output, where date sorting according day/month not year


Viewing all articles
Browse latest Browse all 82358

Trending Articles