Daterangepicker plug-in

Daterangepicker plug-in

xfloydxfloyd Posts: 35Questions: 12Answers: 1

It took me over a day to get this working, so mine as well contribute it. It does not work as inline, so maybe someone can figure that part out.
Here is the code:

            //daterangepicker
            (function( $, DataTable ) {
                'use strict';


                if ( ! DataTable.ext.editorFields ) {
                    DataTable.ext.editorFields = {};
                }

                var _fieldTypes = DataTable.Editor ?
                        DataTable.Editor.fieldTypes :
                        DataTable.ext.editorFields;

                _fieldTypes.daterangepicker = {
                    create: function ( conf ) {

                        conf._input = $('<input/>')
                                .attr( $.extend( {
                                    id: conf.id,
                                    type: 'text'
                                }, conf.attr || {} ) )
                                .daterangepicker( conf.opts || {} );

                        return conf._input[0];
                    },

                    get: function ( conf ) {
                        $(conf._input).data('daterangepicker').elementChanged(); //Update dates of the picker from input
                        return conf._input.val();
                    },

                    set: function ( conf, val ) {
                        conf._input.val( val );
                    }

                };

            })(jQuery, jQuery.fn.dataTable);****

Here is how to use it:

fields: [{
                    label: "Daterangepicker:",
                    name: "daterangepicker_filed",
                    type: "daterangepicker",
                    opts: {}
                }]

Replies

  • allanallan Posts: 63,678Questions: 1Answers: 10,497 Site admin

    Absolutely awesome - thanks for sharing this with us!

    Regards,
    Allan

This discussion has been closed.