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. Otherwise, the column headers do not match up with the body columns.
Is there any way of automatically matching these up, while still allowing the column widths to be defined by the length of the content in the columns (as is the normal table behavior).
I've been working on this today, too. What I've come up with involves adding an onSuccess handler and figuring out what the maximum size of each column is between the header and the body, then setting the width of both to the maximum for that column.
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;
}
}