$.fn.dataTable.render.datetime combine with render: function(data, type, row)

$.fn.dataTable.render.datetime combine with render: function(data, type, row)

Loren MaxwellLoren Maxwell Posts: 387Questions: 94Answers: 10

Similar to this post: https://datatables.net/forums/discussion/comment/134939/

I'd like to pass the data through to the datetime plugin, such as making a sentence with the date rendered in a specific format:

var datetimeRenderer = $.fn.dataTable.render.datetime().display;

render: function(data, type, row){
        return 'From ' + datetimeRenderer( row.start_date, 'MMM DD, YYYY') + ' to ' + datetimeRenderer( row.end_date, 'MMM DD, YYYY');
    }
}

However looks like the plugin as written won't allow me to pass a parameter in the same way that I can with the text renderer.

Am I correct or overlooking something?

Answers

  • Loren MaxwellLoren Maxwell Posts: 387Questions: 94Answers: 10

    I'm waaaaay overthinking this, aren't I?

    Is it just as simple as using the moment.js library directly?

    render: function(data, type, row){
            return 'From ' + moment(row.start_date).format('MMM DD, YYYY') + ' to ' + moment(row.end_date).format('MMM DD, YYYY');
        }
    }
    
This discussion has been closed.