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

Resizable column bug with hidden columns #153

Open Diliz opened 8 years ago

Diliz commented 8 years ago

Hi again,

I found the width is not applied to the good column when there's an hidden one before it, when we try to resize it.

In the dragend function:

var n = this.colresize.n;
var nw = this.colresize.nw;
$('th:visible div:eq(' + n + ')', this.hDiv).css('width', nw);
this.bDiv.style.display = 'none';
var rows = $('tr', this.bDiv), div;
for(var i =0, lim = rows.length; i < lim; i++) {
    div = rows[i].children[n].firstChild;
    div.style.width = nw + 'px';
    g.addTitleToCell(div);
}

For the first row, the column's names, we get the good column with the selector :visible in it, so the hidden columns are not taken by it.

But for the other rows, with the datas, there's no check, so when you want to resize a column with an hidden one before it, the width will get applied to a wrong column.

So what I did is to check if a children before the column I want to resize have a display non affected to it, like this:

var n = this.colresize.n;
var nw = this.colresize.nw;
$('th:visible div:eq(' + n + ')', this.hDiv).css('width', nw);
this.bDiv.style.display = 'none';
var rows = $('tr', this.bDiv), div;
for (var j = 0; j <= n; j++) {
    if($(rows[0].children[j]).css("display") == "none") {
        n++;
    }
}
for(var i =0, lim = rows.length; i < lim; i++) {
    div = rows[i].children[n].firstChild;
    div.style.width = nw + 'px';
    g.addTitleToCell(div);
}

If you think of somethings better tell me, again, thanks for reading.