I'm not sure that it will fix all your problem, but in my case I use forceFitColumns , and then depending on how I want my column to respond to size, I will use a combination of minWidth and width , and in some cases those which will never exceed some width, then I would use maxWidth . Now the problem is that when setting the parameter minWidth the same as maxWidth , this, of course, will make it unrecoverable, think that you set the minimum and maximum, SlickGrid respects it, now it can size it afterwards. I also have my grid, which occupies 95% of the width of my screen, so I have a small addition on the side, and with it I use automatic resizing using jQuery.
Here is my code:
// HTML Grid Container <div id="myGridContainer" style="width:95%;"> <div class="grid-header" style="width:100%"> <label>ECO: Log / Slickgrid</label> <span style="float:right" class="ui-icon ui-icon-search" title="Toggle search panel" onclick="toggleFilterRow1()"></span> </div> <div id="myGrid" style="width:100%;height:600px;"></div> <div id="myPager"></div> </div> // My SlickGrid Options var options = { enableCellNavigation: true, forceFitColumns: true }; // The browser auto-resize $(window).resize(function () { $("#myGrid").width($("myGridContainer").width()); $(".slick-viewport").width($("#myGrid").width()); grid.resizeCanvas(); });
EDIT
I was also annoyed by the fact that using all of these elements prevents you from resizing the column. I came to another solution, much later, which makes the fields expand (gain width) and does not block you after resizing. So this is a new solution, which I believe gives you exactly what you are looking for ... First of all, remove the maxWidth property and use only minWidth and width , in fact you could probably only use width if you are wanted . Now, unfortunately, I had to change 1 main slick.grid.js file to the following code:
//-- slick.grid.js --// // on line 69 insert this code autoExpandColumns: false, // on line 1614 PREVIOUS CODE if (options.forceFitColumns) { autosizeColumns(); } // on line 1614 change to this NEW CODE if (options.forceFitColumns || options.autoExpandColumns) { autosizeColumns(); }
and then back to the definition of my grid, I will replace my previous parameters with the following:
// My NEW SlickGrid Options var options = { enableCellNavigation: true, forceFitColumns: false, // make sure the force fit is false autoExpandColumns: true // <-- our new property is now usable };
with this new change, it has some strength functionality that fits (expands), but does not limit you after you resize the columns after this happens. I also tested it with a Picker column if you hide a column that resizes the rest accordingly. I also modified the slick.columnpicker.js file to include a checkbox for this property, but this is completely optional ... I can add code for this if one of you wants this too. Voila !!! :)
CHANGE No. 2
I realized much later that there is no need to modify the main file, we can just call grid.autosizeColumns() after creating the grid. Like this
var options = { forceFitColumns: false }; grid = new Slick.Grid("#myGrid", data, columns, options);
This will automatically resize the columns to fit the screen on first boot, but will not give you the forceFitColumns flag forceFitColumns .