Consistent grid headers with Flexigrid ?

前端 未结 12 1046
长发绾君心
长发绾君心 2021-02-03 10:05

So I\'m trying to use the flexigrid plugin. It looks like it\'s going to work great aside from the fact that it looks like you have to manually set the column widths. Otherwis

12条回答
  •  北海茫月
    2021-02-03 10:57

    I've gotten this to work (at least partially). The problem I was having with my previous iteration (which was also a problem with tvanfosson's implementation) was that once you resized the headers, then the "drag" bars would not be aligned with the new column widths.

    My current implementation is below, which works in Firefox 3.5 and Chrome. Unfortunately, there is some exception being thrown in IE (all versions) that is rather disconcerting. I will debug further on Monday:

    $(".flexigrid").each(function() {
        var grid = $(this);
        var headers = grid.find(".hDiv thead th");
        var row = grid.find(".bDiv tbody tr:first");
        var drags = grid.find("div.cDrag div");
        if (row.length >= 1) {
            var cells = row.find("td");
            var offsetAccumulator = 0;
            headers.each(function(i) {
                var headerWidth = $(this).width();
                var bodyWidth = cells.eq(i).width();
                var realWidth = bodyWidth > headerWidth ? bodyWidth : headerWidth;
    
                $(this).width(realWidth);
                cells.eq(i).width(realWidth);
    
                var drag = drags.eq(i);
                var dragPos = drag.position();
                var offset = (realWidth - headerWidth);
                var newPos = dragPos.left + offset + offsetAccumulator;
                offsetAccumulator += offset;
                drag.css("left", newPos);
            });
        }
    });
    

提交回复
热议问题