Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dt.render.date should check for a null value #66

Open
challgren opened this issue Aug 23, 2018 · 3 comments
Open

dt.render.date should check for a null value #66

challgren opened this issue Aug 23, 2018 · 3 comments

Comments

@challgren
Copy link

When using the provided dt.render.date if the date passed is null an error will occur.

@ypnos-web
Copy link
Owner

This is in line with the default renderer. What would you want it to do/render in case of missing date? Do you think the behavior should be configurable (e.g. a 'fallback text' argument)?

I am also open for a pull request in this matter.

@challgren
Copy link
Author

Well so here's one thing I found out. If you are storing the data in the DATE format it is returned as a DATE relative to UTC even if you override the server timezone and the database timezone. I do think the fallback text would be a good option. Below is a sample of what my custom render is.

$.fn.dataTable.render.date = function (fallback)
{
    return function (data, type, full, meta)
    {
        if (type === 'display') {
            if (data) {
                var date = new Date(data.toString().substring(0, 4), (parseInt(data.toString().substring(5, 7)) - 1), data.toString().substring(8, 10));
                return date.toLocaleDateString(document.documentElement.lang);
            } else if (fallback !== undefined) {
                return fallback;
            } else {
                return data;
            }
        }
        return data;
    }
};
$.fn.dataTable.render.date_time = function (fallback) {
    return function (data, type, full, meta)
    {
        if (type === 'display') {
            if (data) {
                var date = new Date(data);
                return date.toLocaleDateString(document.documentElement.lang) + ' ' + date.toLocaleTimeString(document.documentElement.lang);
            } else if (fallback !== undefined) {
                return fallback;
            } else {
                return data;
            }
        }
        return data;
    }
};

@ypnos-web
Copy link
Owner

Yes, your observation is correct. What I don't understand is why you use custom parsing of the string in the first method.

Would you like to prepare a pull request with the fallback mechanics?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants