How to call a function in "render"? (inside "data" - "columns")

How to call a function in "render"? (inside "data" - "columns")

dataphpmysqldataphpmysql Posts: 65Questions: 17Answers: 0


So I'm trying to call a function on render that's inside the data which is inside the columns option. I'm using a function inside render to change the date format. But since I'm using it a lot in several columns, I would like to call the function instead of typing the whole block every time - in order to make the code cleaner. The function I'm trying to call is xDateFormat which is at the bottom of the script. I think I'm making the call incorrectly, any hints on how to make ti work?

Here is what I have so far:

        $(document).ready(function () {
            var table = $('#dtBasicExample').DataTable({
                ajax: {
                    method: 'GET',
                    url: '',
                    dataSrc: ''
                columns: [
                        "className": 'details-control',
                        "orderable": false,
                        "data": null,
                        "defaultContent": ''
                    { "data": "ID" },
                    { "data": "Title" },
                        "data": "Date",
                        "render": xDateFormat(data, type, row)
            $('#dtBasicExample tbody').on('click', 'td.details-control', function () {
                var tr = $(this).closest('tr');
                var row = table.row(tr);

                if (row.child.isShown()) {
                else {

        function xDateFormat(data, type, row) {
            var xformatDate = data.slice(0, 10);
            var xreplaceCharDate = xformatDate.replace(/-/g, "/");
            var dateSplit = xreplaceCharDate.split('/');
            return type === "display" || type === "filter" ?
                dateSplit[1] + '/' + dateSplit[2] + '/' + dateSplit[0] :

This question has an accepted answers - jump to answer


Sign In or Register to comment.