jspreadsheet / ce

Jspreadsheet is a lightweight vanilla javascript plugin to create amazing web-based interactive tables and spreadsheets compatible with other spreadsheet software.
https://bossanova.uk/jspreadsheet/v4
MIT License
6.72k stars 824 forks source link

The position of Frozen columns is incorrect if .hideIndex() is used. #1104

Open kunalshewale opened 4 years ago

kunalshewale commented 4 years ago

Hi,

While working on my requirement I observed that the position of the frozen column is not set correctly if your index number column is hidden. I found the solution, posted it below.

obj.updateFreezePosition = function() {
            scrollLeft = obj.content.scrollLeft;
            var width = 0;
            if (scrollLeft > 50) {
                for (var i = 0; i < obj.options.freezeColumns; i++) {
                    if (i > 0) {
                        width += parseInt(obj.options.columns[i-1].width);
                    }
                    obj.headers[i].classList.add('jexcel_freezed');
                    obj.headers[i].style.left = width + 'px';
                    for (var j = 0; j < obj.rows.length; j++) {
                        if (obj.rows[j] && obj.records[j][i]) {
                            var indexColumnWidth = (obj.table.classList.contains('jexcel_hidden_index') ? 1 : 51)
                            var shifted = (scrollLeft + (i > 0 ? obj.records[j][i-1].style.width : 0)) - indexColumnWidth + 'px';
                            obj.records[j][i].classList.add('jexcel_freezed');
                            obj.records[j][i].style.left = shifted;
                        }
                    }
                }
            } else {
                for (var i = 0; i < obj.options.freezeColumns; i++) {
                    obj.headers[i].classList.remove('jexcel_freezed');
                    obj.headers[i].style.left = '';
                    for (var j = 0; j < obj.rows.length; j++) {
                        if (obj.records[j][i]) {
                            obj.records[j][i].classList.remove('jexcel_freezed');
                            obj.records[j][i].style.left = '';
                        }
                    }
                }
            }

            // Place the corner in the correct place
            obj.updateCornerPosition();
        }
whyJoe commented 4 years ago

Could you list more code ,pls?I also met this problem ,thx!

kunalshewale commented 4 years ago

Could you list more code ,pls?I also met this problem ,thx!

Can you please elaborate, what exactly you want within the code?

whyJoe commented 4 years ago

emmm ,i don't konw how use your solution in my code.

kunalshewale commented 4 years ago

We can't fix it from external code, we have to make the adjustment in jexcel.core.js file. The above snippet is from the respective file.

whyJoe commented 4 years ago

I replaced the source code with your code directly,but it not work.So I don't konw how to do....

kunalshewale commented 4 years ago

Please see if the following helps you.

https://github.com/kunalshewale/jexcel/commit/6edc3165f90fd2dfe917cfda607e533877063107

In case you still have an issue, please share codepen link where I can take a look.

whyJoe commented 4 years ago

Excure me ,can you leave a email?I don't konw how to post pictures here,hhhh

fredchengfei commented 4 years ago

I found that frozen columns not effect when I didnot set table width, dou you confused with the same question

kunalshewale commented 4 years ago

I found that frozen columns not effect when I didnot set table width, dou you confused with the same question

I am not sure what you are implying here. The issue was; if I have a frozen column in the table then while scrolling horizontally the position of the frozen columns were not set correctly.

kunalshewale commented 4 years ago

Excure me ,can you leave a email?I don't konw how to post pictures here,hhhh

Hope, the issue is resolved for you. In case it is not, please drop a message here.

0Chan-smc commented 7 months ago

Can you update this to latest version?