DHTMLX / scheduler

GPL version of JavaScript Event Scheduler
https://dhtmlx.com/docs/products/dhtmlxScheduler/
GNU General Public License v2.0
311 stars 110 forks source link

wrong event section in multiday unit view #30

Closed MrSef217 closed 7 years ago

MrSef217 commented 7 years ago

Hello , we are currently using scheduler v4.3.17 commercial licence.

and our clients started complaining about an issue where the events are created in the wrong section. for example i click section "b" it get created in "c" or "d". i found out that the event during it's creation doesnt have the section id so to fix it i added this line to the function scheduler.addEventNow base.id = this._drag_id = this.uid(); var pr = this._props[this._mode]; if(pr && e){ base[this._props[this._mode].map_to] = this.getActionData(e).section ; }

now the event is created where it should . but there's a new issue , if we create a view unit that has 7 days 7 units , the event is created in wrong section , i think there's is a problem with the way how it's calculated , i tracked the issue to the function scheduler["mouse_"+ name] = function(pos){ //mouse_coord handler in dhtmlxscheduler_units.js.

var section_ind = pos.x % pr.options.length;
var unit_ind = Math.min(section_ind+pr.position,pr.options.length-1);
pos.section = (pr.options[unit_ind]||{}).key;
pos.x = Math.floor(pos.x / pr.options.length);

Thank you.

MrSef217 commented 7 years ago

the bug is also in v4.3.35.

MrSef217 commented 7 years ago

the issue was caused by this line column = x_pos / width;


scheduler._get_column_index = function(x_pos) {
    var column = 0;
    if (this._cols) {

        var width = 0;
        for (var i = 0; i < this._cols.length && !width; i++) {
            width = this._cols[i];
        }

        if (width) {

            //column = x_pos / width; 
            // youssef : not accurate way to calculate sections , sometimes 1px is missing
            var x = 0;
            for(var j=0; this._cols.length ;j++){
                if( x <= x_pos ){
                    x+= this._cols[j];
                }else{
                  column = j;
                  break;
                }
            }

        } else {
            column = 0;
        }

        if (this._ignores)
            for (var i = 0; i <= column; i++)
                if (this._ignores[i])
                    column++;
    }
    return column;
};
```.
AlexKlimenkov commented 7 years ago

Hi, should be fixed in v4.4.0 https://github.com/DHTMLX/scheduler/tree/v4.4.0