paulopmx / Flexigrid

Lightweight but rich data grid with resizable columns and a scrolling data to match the headers, plus an ability to connect to an xml/json based data source using Ajax to load the content.
689 stars 539 forks source link

cDrag (column drag handles) position incorrect when zoomed #120

Open joincamp opened 10 years ago

joincamp commented 10 years ago

Overview: If the page is initially loaded using a preset zoom, the column drag elements will not line up correctly.

Browsers used: Chrome 29, Firefox 17, IE 8

image

Steps to reproduce: 1) Navigate to http://flexigrid.info/ (ensure that browser zoom level is 100% first) 2) Set browser zoom level to >100% (e.g. 175% for the following example) 3) Note that the drag elements line up correctly right now 4) Reload the page. (ensure that your browser zoom level retained. the grid must be initialized at the zoom level) 5) Find a column drag element from a right-most column. (at least 3rd column to demonstrate effect) image

joincamp commented 10 years ago

When initializing cdpad, positional data is truncated when using parseInt.

image

When using the following patch, results are as expected.

<             g.cdpad += (isNaN(parseInt($('div', cdcol).css('borderLeftWidth'))) ? 0 : parseInt($('div', cdcol).css('borderLeftWidth')));
<             g.cdpad += (isNaN(parseInt($('div', cdcol).css('borderRightWidth'))) ? 0 : parseInt($('div', cdcol).css('borderRightWidth')));
<             g.cdpad += (isNaN(parseInt($('div', cdcol).css('paddingLeft'))) ? 0 : parseInt($('div', cdcol).css('paddingLeft')));
<             g.cdpad += (isNaN(parseInt($('div', cdcol).css('paddingRight'))) ? 0 : parseInt($('div', cdcol).css('paddingRight')));
<             g.cdpad += (isNaN(parseInt($(cdcol).css('borderLeftWidth'))) ? 0 : parseInt($(cdcol).css('borderLeftWidth')));
<             g.cdpad += (isNaN(parseInt($(cdcol).css('borderRightWidth'))) ? 0 : parseInt($(cdcol).css('borderRightWidth')));
<             g.cdpad += (isNaN(parseInt($(cdcol).css('paddingLeft'))) ? 0 : parseInt($(cdcol).css('paddingLeft')));
<             g.cdpad += (isNaN(parseInt($(cdcol).css('paddingRight'))) ? 0 : parseInt($(cdcol).css('paddingRight')));
---
>             g.cdpad += (isNaN(Math.round(parseFloat($('div', cdcol).css('borderLeftWidth')))) ? 0 : Math.round(parseFloat($('div', cdcol).css('borderLeftWidth'))));
>             g.cdpad += (isNaN(Math.round(parseFloat($('div', cdcol).css('borderRightWidth')))) ? 0 : Math.round(parseFloat($('div', cdcol).css('borderRightWidth'))));
>             g.cdpad += (isNaN(Math.round(parseFloat($('div', cdcol).css('paddingLeft')))) ? 0 : Math.round(parseFloat($('div', cdcol).css('paddingLeft'))));
>             g.cdpad += (isNaN(Math.round(parseFloat($('div', cdcol).css('paddingRight')))) ? 0 : Math.round(parseFloat($('div', cdcol).css('paddingRight'))));
>             g.cdpad += (isNaN(Math.round(parseFloat($(cdcol).css('borderLeftWidth')))) ? 0 : Math.round(parseFloat($(cdcol).css('borderLeftWidth'))));
>             g.cdpad += (isNaN(Math.round(parseFloat($(cdcol).css('borderRightWidth')))) ? 0 : Math.round(parseFloat($(cdcol).css('borderRightWidth'))));
>             g.cdpad += (isNaN(Math.round(parseFloat($(cdcol).css('paddingLeft')))) ? 0 : Math.round(parseFloat($(cdcol).css('paddingLeft'))));
>             g.cdpad += (isNaN(Math.round(parseFloat($(cdcol).css('paddingRight')))) ? 0 : Math.round(parseFloat($(cdcol).css('paddingRight'))));
joincamp commented 10 years ago

Maintainer: I've not contributed to this project before. Would you like me to check the change from the previous comment in? If so, how do you handle the minified file? Do you only update that on releases?

Nickoladze commented 10 years ago

I get a similar issue whenever I'm at normal zoom level, the issue gets worse the farther right the column resides. See around line 165:

var cdcounter=0;
...
'left': (!(browser.mozilla) ? cdpos - cdcounter : cdpos) + 'px'
...
cdcounter++;

cdcounter is incremented for every column and used only in non-mozilla browsers. Simply removing cdcounter's usage fixes the issue. Confirmed working in latest Chrome, Firefox, IE10, and IE9 (compatibility mode) at the time of writing this comment.

Interestingly enough, I never get this issue with the demo grids on flexigrid's website. Inspecting the handle elements on my website in Chrome doesn't show them inheriting anything CSS styles. Very odd.