CraigCav / Knockout-jqGridBinding

A grid binding plugin for Knockout.js that provides basic integration with the JqGrid plugin for jQuery.
MIT License
37 stars 10 forks source link

Column width for wide tables #12

Open powercat97 opened 10 years ago

powercat97 commented 10 years ago

I had an issue with the column widths in a wide table. I set the width in the style property, however none of the columns were as wide as I had set. When the original table was rendered it seems the widths were squished so the table would fit on the page. Then when the plug-in read the source.width() for each cell, it was too narrow.

I replaced the code at the top of buildColModel with this; it pulls the width from the style property, so page rendering doesn't squish what the grid's designer intended.

$('th', element).each(function () { var source = $(this), width = source.width();

        // powercat97-- Can't use the source.width. In wide grids, it can get  squished. 
       // instead see what was defined in the style width property.
        if ($(this).prop('style') && $(this).prop('style').width) {
            width = $(this).prop('style').width;
        }

        var col = source.attr('id') || source.data().field || $.trim($.jgrid.stripHtml(source.html())).split(' ').join('_'),
            model = { name: col, index: col, width: width },
            template = templates.filter('[data-field="' + model.index + '"]');
CraigCav commented 10 years ago

I've seen this issue myself, although the solution isn't clear-cut as it stems from jqgrid setting fixed widths - presumably to enable column resizing.

The ideal solution would allow the grid to be styled purely in css (no widths set using JavaScript), since this would allow for the grid to resize automatically for different container sizes (for example, when a window is resized).