meetselva / fixed-table-rows-cols

Fixed Table Header and Columns
http://meetselva.github.com/fixed-table-rows-cols/
Other
77 stars 42 forks source link

Optional use of colModal #38

Open henhouseharry opened 8 years ago

henhouseharry commented 8 years ago

Thanks for such a useful script. I have a table with a dynamic number of columns, so using colModal isn't really practical.

If colModal isn't specified the code doesn't guard against this and will raise an exception in Chrome. I had to wrap the code like so:

if(cfg.colModal[i]!=undefined){
    $('td', el).each(function (i, tdel) {
        tdel.style.textAlign = cfg.colModal[i].align;
    });
}

And then:

if(lc.tableWidth!=0)
            $this.width(lc.tableWidth);

I only wanted the first column to be fixed (unmovable), and this basically works. However if the first row is a title and has a different colSpan for the rest of the table it would duplicate the first column (in IE) or the first data column (Chrome\Firefox). That's a bug.

I had to repeatidly remove the duplicated column until it disappeared.

            var cols = $("table").find("tr:nth-child(3) td");
            var count = 0;
            for(var i = 0; i < cols.length; i++)
            {
               var colspan = cols.eq(i).attr("colspan");
               if( colspan && colspan > 1)
               {
                  count += colspan;
               }else{
                  count++;
               }
            }
            for(var n = 0; n < count; n++)
            {
                        $('td:nth-child(2), th:nth-child(2)', 'table:eq(1) tr').remove();
            }

This feels like a bad hack and I would rather the script was improved for this kind of usage.