简体   繁体   English

Kendo Grid初始列大小

[英]Kendo Grid Initial Column Size

I am trying to get my initial column widths correct for my Kendo Grid. 我试图使我的Kendo Grid的初始列宽正确。 This is driving me crazy! 这真让我抓狂!

My grid is like the following... 我的网格如下所示...

<table class="MyTableClass">
    <thead>
        <tr>
            <th>
                @(Html.Kendo().Grid(Model.MyModel).Name("myGrid").HtmlAttributes(new { @class = "shadow", style = "height:40%;width:100%" })
                    .Extra(false)
                    .Operators(...)
                    .Resizable(resize => resize.Columns(true))
                    .Sortable().Scrollable().Pageable().Selectable(selectable => selectable.Mode(GridSelectionMode.Single))
                    .DataSource(dataSource => dataSource.Ajax().ServerOperation(false).PageSize(25))
                    .Columns(columns =>
                        columns.Bound(p => p.Property1).Title("MyProperty1").ClientTemplate("...");
                        columns.Bound(p => p.Property2).Title("MyProperty2").ClientTemplate("...").Width(100);
                        columns.Bound(p => p.Property3).Title("MyProperty3").ClientTemplate("...");
                        columns.Bound(p => p.Property4).Title("MyProperty4").ClientTemplate("...").Width(100);

... ...

as you can see I have set widths for all but two of the columns which I want to take up the rest of whatever the width is. 如您所见,我为除两列之外的所有列设置了宽度,无论宽度多少,我都想占用其余的列。 This works great except when the width is small the two columns without the explicit width setting are basically zero width and therefore seems missing. 这非常有用,除了当宽度较小时,没有显式宽度设置的两列基本上为零宽度,因此似乎丢失了。

I am trying to set a minimum width on the columns (that don't have the width explicit) where if it is less than 100 then it sets the width to 100. 我正在尝试在列上设置最小宽度(没有明确的宽度),如果该宽度小于100,则将宽度设置为100。

I've tried everything I can think of and got close with calling the following on document load... 我已经尝试了所有可以想到的方法,并在文档加载时调用了以下内容...

function setColumnMinimumWidths() {
    $("#myGrid colgroup col").each(function () {
        if ($(this).width() < 100) {
            $(this).css("width", "100px");
        }
    })
}

this does the trick but then after resizing the window all the other columns now resize evenly (ignoring the explicit widths). 这可以解决问题,但是在调整窗口大小之后,其他所有列现在都将均匀调整大小(忽略显式宽度)。

any kendo or javascript experts out there that have any ideas? 有任何剑道或javascript专家有什么想法吗?

If you have in your grid some columns that have fixed grid and some doesn't, columns with width property will have provided width and rest of the columns will take rest of the place divided equally. 如果网格中的某些列具有固定的网格,而有些则没有,具有width属性的列将提供width,其余的列将平均分配其余的位置。

The simplest thing you can do is set minimum width of the grid in css: 您可以做的最简单的事情是在CSS中设置网格的最小宽度:

#grid{
    min-width: 400px;
}

Check this example: http://dojo.telerik.com/OHOku 检查此示例: http : //dojo.telerik.com/OHOku

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM