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 540 forks source link

Storing width in cookies buggy after reordering columns #49

Open uberthold opened 11 years ago

uberthold commented 11 years ago

The dragEnd function uses the columns current index in the table as displayed for all operations. A columns colresize.n value can differ.

However, the cookie part uses the p.colModel to look up the column's name, which never changes. This potentially stores the new column width for the wrong column.

The issue can be resolved by replacing line 231 var name = p.colModel[n].name; with var name = $('th', g.hDiv).eq(n).attr('abbr');

I'm not sure this is the best way to do it...

uberthold commented 11 years ago

Actually, the fix I previously provided is also buggy. If you resize any column whose (current) display index is bigger than that of a hidden column, it would fail. Also, like I stated before, it's not the best way to do it, as it relies on the "abbr" attribute, which is only there when the columns are named and declared as sortable.

I believe the following is better:

// Get the column's ID via the axis attribute. This attribute is always present, // and addData uses the same method of getting the index within colModel, which doesn't change. var cid = $('th:visible', this.hDiv).eq(n).attr('axis').substr(3);

// Get the name as declared in the colModel var name = p.colModel[cid].name;