Ross是正確的...如果網格的寬度太小,autowidth列會在分配固定列後得到剩餘寬度。這通常是零,然後你卡住了。
我的解決方法(HACK !!!)是在網格上設置一個最小寬度,該最小寬度是固定寬度的總和加上可以在自動寬度列之間平分的額外數量。然後我調用一個自定義的ensureMinWidth()函數,該函數根據最小寬度修正網格的表格和標題元素的寬度,以便autowidth列獲得分配給它們的一些空間。
這很不好,但它可以防止列消失。
設定最小寬度:
<style>
/* Force initial min-width to fit all the columns so that the Title column
(which is set to take up the remaining space) will not disappear when remaining space is 0 on initial screen load.
Grid.ensureMinWidth() javascript will deal with it at runtime.
*/
#grid .k-grid-header-wrap > table, /* header table */
#grid .k-grid-content table, /* data table, no virtual scrolling */
#grid .k-virtual-scrollable-wrap table /* data table, with virtual scrolling */ {
min-width: 600px; /* Width of fixed columns plus enough space so that autowidth columns don't disappear, i.e. min column width of auto columns */
}
</style>
的輔助函數:
<script>
/* Ensures that a grid will that has too many columns to fit in the viewport will not shrink dynamic width
columns to 0 if there is no space left and then makes sure that the column resizing continues to function
without weird jumping around/misalignment with the cursor that the out-of-the-box solution creates.
NOTE:
1. MUST be used in conjunction with the grid tables being given an initial min-width at design-time.
2. Due to the way Kendo binds the Grid's resizable with ajax data, this must be called on every dataBound
rather than just during Grid initialization. */
kendo.ui.Grid.prototype.ensureMinWidth = function() {
if (this.resizable) {
this.resizable.bind("resize", function (e) {
var minTableWidth,
th = $(e.currentTarget).data("th"),
grid = th.closest(".k-grid").getKendoGrid();
if (e.x.delta > 0) {
minTableWidth = grid.tbody.closest("table").width();
}
else {
minTableWidth = grid.tbody.closest("table").width() + e.x.delta;
}
if (grid.options.scrollable) {
grid.thead.closest("table").css({ "min-width": minTableWidth });
}
grid.tbody.closest("table").css({ "min-width": minTableWidth });
});
}
}
</script>
然後你只需要調用ensureMinWidth()在網格中的數據綁定事件。
單獨使用最小寬度的設置可能適用於您,但我發現需要在窗體上調整網格以佔用瀏覽器視口中剩餘的空間的幫助器功能...您的結果可能會有所不同。
例子:http://dojo.telerik.com/@Stephen/IlUYun
我認爲,減去固定寬度的列的總和之後,從電網寬度遺留在自動寬域之間進行分配。 –
你是對的,這就是爲什麼它得到零長度。我需要擊敗那個目的。 –