mominsamir / smDateTimeRangePicker

Angular Material Date Picker, DateTime Picker, Date Range Picker, Date Time range picker
http://mominsamir.github.io/smDateTimeRangePicker/
MIT License
130 stars 50 forks source link

sm range picker issue #154

Closed vamsideepak closed 7 years ago

vamsideepak commented 7 years ago

i can't to set(bind) default range(example today date) in sm range picker. can anyone help me in this ? am using moment.js

oleg-demkovych commented 7 years ago

in config function:

pickerProvider.setRangeDefaultList([
        {
          label: 'All',
          startDate: null,
          endDate: null
        }, {
          label: 'Today',
          startDate: moment().utc().startOf('day'),
          endDate: moment().utc().endOf('day')
        }, {
          label: 'Yesterday',
          startDate: moment().subtract(1, 'd').startOf('day'),
          endDate: moment().subtract(1, 'd').endOf('day')
        }, {
          label: 'Current Week',
          startDate: moment().startOf('week'),
          endDate: moment().endOf('week')
        }, {
          label: 'Current Month',
          startDate: moment().startOf('month'),
          endDate: moment().endOf('month')
        }, {
          label: 'Current Year',
          startDate: moment().startOf('year'),
          endDate:  moment().endOf('year')
        }]);
oscar09 commented 7 years ago

It should be fixed now in the master branch. This functionality was broken by commit ff038cf739931bac35a2366d1a41a9a15c3e27c1

The correct way to initialize the model would be the following:

    vm.employee = {};
    vm.employee.default = {
        startDate: moment(),
        endDate: moment().add(1, 'days')
    };

<sm-range-picker-input
                fname="Date of Pay"
                label="Date of Pay"
                form="test"
                ng-model="vm.employee.default"
                flex="50"
                format="DD-MMM-YYYY"
                floating-label="true"
                divider="To"
                week-start-day="Monday"
                custom-to-home="true"
                allow-clear="true"
                allow-empty="true"
                on-range-select="vm.dayofPaySelected(range)">
            </sm-range-picker-input>