fragaria / angular-daterangepicker

Angular.js wrapper for dangrossman/bootstrap-daterangepicker
MIT License
519 stars 372 forks source link

Get the label when pre-defined range is clicked. #254

Closed omelsoft closed 5 years ago

omelsoft commented 7 years ago

Hello,

The following code using the standard implementation logs the "label" whenever a pre-defined range is selected. The label is the key index of the pre-defined ranges.

$('#demo').daterangepicker({
    showWeekNumbers: true,
    ranges: {
    'Today': [moment(), moment()],
    'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
    'Last 7 Days': [moment().subtract(7, 'days'), moment()],                           
    'Last 30 Days': [moment().subtract(30, 'days'), moment()]
    },
    opens: "left",
    startDate: moment().subtract(30, 'days'),
    endDate: moment()
}, function(start, end, label) {
  console.log("Range: ", label);
});

Is this already supported or has anyone already raised this concern?

Thank you.

atentis commented 7 years ago

Did you manage to find a way to do this? I need to get the range label as well.

atentis commented 7 years ago

I was able to add this functionality by adding the label param and the rangeLabel property in the angular-daterangepicker.js.


        }), function (start, end, **label**) {  
            return $scope.$apply(function() {
              return $scope.model = opts.singleDatePicker ? start : {
                startDate: start,
                endDate: end,
                **rangeLabel: label**
              };
            });
          });