我有两个预定义的日期范围,如“当前月份”和“当前季度”。目前,这两个范围代表相同的日期值(因为刚刚开始的季度和月份)。当我想选择“当前季度”时,它会自动选择“当前月份”。无法选择“当前季度”,该按钮未处于活动状态。这看起来不像是一个用户友好的行为。是否有任何配置允许用户选择具有相同值的不同日期范围?
发布于 2021-07-29 21:29:37
不幸的是,ngx-daterangepicker-material的设计不允许多个日期完全相同的范围。我能够重现你在这里看到的症状:Stackblitz
看一下您正在使用的包的代码,您将在calculateChosenLabel()方法中看到:
calculateChosenLabel () {
if (!this.locale || !this.locale.separator) {
this._buildLocale();
}
let customRange = true;
let i = 0;
if (this.rangesArray.length > 0) {
for (const range in this.ranges) {
if (this.ranges[range]) {
if (this.timePicker) {
const format = this.timePickerSeconds ? 'YYYY-MM-DD HH:mm:ss' : 'YYYY-MM-DD HH:mm';
// ignore times when comparing dates if time picker seconds is not enabled
if (this.startDate.format(format) === this.ranges[range][0].format(format)
&& this.endDate.format(format) === this.ranges[range][1].format(format)) {
customRange = false;
this.chosenRange = this.rangesArray[i];
break;
}
} else {
// ignore times when comparing dates if time picker is not enabled
if (this.startDate.format('YYYY-MM-DD') === this.ranges[range][0].format('YYYY-MM-DD')
&& this.endDate.format('YYYY-MM-DD') === this.ranges[range][1].format('YYYY-MM-DD')) {
customRange = false;
this.chosenRange = this.rangesArray[i];
break;
}
}
i++;
}
}它循环遍历您指定的范围,并匹配根据该范围选择的开始和结束日期。
2.除非您显示时间选择器,否则它会忽略时间值,因此即使尝试使用时间偏移量来修改它也不会起作用
目前没有任何标志或选项可以覆盖此设置。
看起来您最好的选择是使用Open a new issue来请求使用唯一的范围标识符,而不仅仅是比较日期
或者导入项目的源代码,并根据自己的需要进行修改
https://stackoverflow.com/questions/68536772
复制相似问题