New to Telerik UI for ASP.NET MVC? Start a free 30-day trial
Remove Trailing Space When Resizing Grid Columns
Environment
Product | Telerik UI for ASP.NET MVC Grid |
Description
How can I avoid the rendering of the blank space after the last column when the columns are resized to less than the width of a resizable Grid for ASP.NET MVC?
Solution
Add an empty column to the Grid. You can manually calculate its width, so that it fills the available space when the columns are resized. If the columns are wider than the Grid, the empty column is hidden.
Grid.cshtml
@(Html.Kendo().Grid<MyGrid.Models.OrderViewModel>()
.Name("grid")
.Pageable()
.Scrollable()
.HtmlAttributes(new { style = "height:430px; width: 750px;" })
.Columns(columns =>
{
columns.Bound(o => o.OrderDate).Width(110).Format("{0:MM/dd/yyyy}");
columns.Bound(o => o.ShipCity).Width(110);
columns.Bound(o => o.ShipName).Width(200);
columns.Bound(o => o.Freight).Width(200);
columns.Bound(o => o.OrderID).Width(60).Title("ID");
columns.Bound("").ClientTemplate(" ");
})
.Events(ev=>ev.DataBound("onDataBound").ColumnResize("onColumnResize"))
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(15)
.Read(read => read.Action("Orders_Read", "Grid"))
)
.Resizable(resize => resize.Columns(true))
)