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: 52,525Questions: 1Answers: 8,019 Site admin

    Absolutely awesome - thanks for sharing this with us!

    Regards,
    Allan

This discussion has been closed.