Consistent grid headers with Flexigrid ?

前端 未结 12 1070
长发绾君心
长发绾君心 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:42

    This code work fine in my project. It's similar to other answers.

    $("#my_table").flexigrid({
        ...
        onSuccess: function(){
            columnWidth();
            $(window).resize(function(){
                columnWidth();
            });
        }
    });
    
    function columnWidth(){
        var num_col = 0;
        //Work with the columns width of the first row of body
        $("#row1 td").each(function(td){
            //row's column's width greater than header's column's width 
            if($(this).width() > $("th[axis='col"+num_col+"']").width()){
                $("th[axis='col"+num_col+"']").width($(this).width());
                $("th[axis='col"+num_col+"']").css({"min-width":$(this).width()});
            }
            //header's column's width greater than row's column's width
            else if($("th[axis='col"+num_col+"']").width() > $(this).width()){
                $("td[abbr='"+$(this).prop('abbr')+"']").width($("th[axis='col"+num_col+"']").width());
                $("td[abbr='"+$(this).prop('abbr')+"']").css({"min-width":$("th[axis='col"+num_col+"']").width()});
            }
            ++num_col;
        });
    }
    

    I hope this has solved your problems.

提交回复
热议问题