Skip to content

Instantly share code, notes, and snippets.

@alarie
Last active October 23, 2023 19:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alarie/e66376ea8e06070864e1ba751043d05a to your computer and use it in GitHub Desktop.
Save alarie/e66376ea8e06070864e1ba751043d05a to your computer and use it in GitHub Desktop.
A little extension class of of the Handsontable DateEditor that makes sure the datepicker opens to the top if needed. (Needs modifications for other directions) See https://github.com/handsontable/handsontable/issues/3483
const Base = (Handsontable.editors.DateEditor as any).prototype as any
const DateEditorHelper = Base.extend()
DateEditorHelper.prototype.showDatepicker = function(...args: any[]) {
Base.showDatepicker.apply(this, ...args)
const offset = (this.TD as HTMLElement).getBoundingClientRect()
const picker = this.$datePicker.el as HTMLElement
const pickerRect = picker.getBoundingClientRect()
if (
(this.cellProperties &&
this.cellProperties.datePickerConfig &&
this.cellProperties.datePickerConfig.position &&
this.cellProperties.datePickerConfig.position.indexOf("top") !== -1)
||
offset.top >= window.innerHeight - pickerRect.height
) {
this.datePickerStyle.top = (window.pageXOffset + offset.top - pickerRect.height) + "px"
}
}
@bturner1273
Copy link

bturner1273 commented Oct 23, 2023

line 14 should be:

offset.bottom >= window.innerHeight - pickerRect.height

no?

because if you don't have the picker anchored to the top (which you are already checking for) then it is gonna be anchored on the bottom and has an additional offset the height of the TD element

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment