handsontable icon indicating copy to clipboard operation
handsontable copied to clipboard

0.12.2 issue: Datepicker position in scrollable table

Open yuwong opened this issue 11 years ago • 8 comments

Please see http://jsfiddle.net/289603vk/2/

The position of the datepicker is an issue after scrolling

yuwong avatar Dec 08 '14 14:12 yuwong

Same issue here :( Temporarily i'm using HTML5 datepicker in Chrome and custom editor for input type 'date' based on example for input type 'password'.

mtomlak avatar Dec 25 '14 23:12 mtomlak

@mikesvk can you post the code? I am also encountering this issue...

kevin-j-morse avatar Dec 27 '14 21:12 kevin-j-morse

Removing overflow: auto or overflow: scroll fixes this but isn't my preferred solution.

kevin-j-morse avatar Dec 27 '14 21:12 kevin-j-morse

Sure, but table wouldn't be scrollable for me and would break my page layout and putting it in iframe isn't my preferred solution either (trying it brought in other issues with focus and navigating through table). As i said, my solution is only tested in Chrome using it's HTML5 datepicker, as i don't need cross-browser compatibility in my intranet project so it's ok for me till HOT will fix the issue. The code is:

CustomDateEditor.prototype.createElements = function () {
    //Call the original createElements method
    Handsontable.editors.TextEditor.prototype.createElements.apply(this, arguments);

    //Create date input and update relevant properties
    this.TEXTAREA = document.createElement('input');
    this.TEXTAREA.setAttribute('type', 'date');
    this.TEXTAREA.className = 'handsontableInput';
    this.textareaStyle = this.TEXTAREA.style;
    this.textareaStyle.width = 0;
    this.textareaStyle.height = 0;

    //Replace textarea with date input
    Handsontable.Dom.empty(this.TEXTAREA_PARENT);
    this.TEXTAREA_PARENT.appendChild(this.TEXTAREA);
};

and in column settings i got

columns:
    { type: 'date', editor: CustomDateEditor }

mtomlak avatar Dec 27 '14 22:12 mtomlak

Chrome's datepicker mentioned above only works with RFC format yyyy-mm-dd, so i'm also using two tiny custom functions to convert date from my local format to RFC and backwards, if your'e happy enough with Chrome datepicker, i'll send you the other code as well.

I'm pretty sure fixing the real issue with jquery-ui datepicker wouldn't be difficult but i didn't want to do any changes in original handsontable js file so i can just include this piece of code (and even get rid of dependency on jquery-UI) In my opinion the issue might be there because datepicker element it's created outside of scrollable container so either it needs to be created within this element or repositioned according to actual scroll position.

mtomlak avatar Dec 27 '14 22:12 mtomlak

@mikesvk Thanks! I implemented your workaround (I was already using RFC so it was straightforward) and then looked into this a little more.

Replacing Handsontable.Dom.offset(this.TD); with $(this.TD).offset(); fixes things for me. It seems the Handsontable.DOM.offset function is just implemented wrong. Not really sure why HOT felt the need to reinvent the wheel because it's just asking for mistakes like this to pop up.

Kinda nervous about replacing the other 22 occurrences of Dom.offset with the jQuery version but it did fix things in this situation.

EDIT: For those wondering, I made the substitution in the DateEditor.prototype.showDatepicker function.

kevin-j-morse avatar Dec 28 '14 05:12 kevin-j-morse

@mikesvk reading your previous comment I think it makes sense now. The Dom.offset is not actually compatible with jQuery.offset because it finds an elements position inside of the Handsontable whereas the jQuery.offset is defined as finding the offset relative to the page.

This actually works in all the other cases because the elements created are inside of the Handsontable and so the "offsets" are correct. In this case it does not work because the jquery-ui datepicker is created outside of the handsontable and therefore needs the offset from the page (as returned by the jQuery version of the function).

kevin-j-morse avatar Dec 28 '14 05:12 kevin-j-morse

For me, I can't use the date input type due to supporting ancient browsers...

My current (non-ideal) workaround is replacing document.body.appendChild(this.datePicker); with this.instance.rootElement.appendChild(this.datePicker); from DateEditor.prototype.createElements in 0.12.2, as well as a fixed offset change to this.datePickerStyle.top in DateEditor.prototype.showDatepicker

Changing the parent the datepicker is attached to, so the position is aligned correctly, at the cost of datepicker appearing within the overflow hidden when near bottom of visible rows, requiring further scrolling to access

@kevin-j-morse I've tested your solution of using JQuery offset, which works well even at the bottom of the visible rows, as the datapicker is attached to the document as originally intended, my only issue is the datepicker remains in the same position relative to the page after scrolling the table, probably just have to add something to hide any visible datepickers onScroll

yuwong avatar Jan 05 '15 10:01 yuwong