解决方法
我今天也在这个工作.我想到的是添加一个onSuccess处理程序,并找出标题和主体之间每列的最大大小,然后将两者的宽度设置为该列的最大值.
grid.flexigrid({ ...other setup... onSuccess: function() { format(); }); } }); function format() { var gridContainer = this.Grid.closest('.flexigrid'); var headers = gridContainer.find('div.hDiv table tr:first th:not(:hidden)'); var drags = gridContainer.find('div.cDrag div'); var offset = 0; var firstDataRow = this.Grid.find('tr:first td:not(:hidden)'); var columnWidths = new Array( firstDataRow.length ); this.Grid.find( 'tr' ).each( function() { $(this).find('td:not(:hidden)').each( function(i) { var colWidth = $(this).outerWidth(); if (!columnWidths[i] || columnWidths[i] < colWidth) { columnWidths[i] = colWidth; } }); }); for (var i = 0; i < columnWidths.length; ++i) { var bodyWidth = columnWidths[i]; var header = headers.eq(i); var headerWidth = header.outerWidth(); var realWidth = bodyWidth > headerWidth ? bodyWidth : headerWidth; firstDataRow.eq(i).css('width',realWidth); header.css('width',realWidth); drags.eq(i).css('left',offset + realWidth ); offset += realWidth; } }