Responsive Columns
The Telerik UI for ASP.NET MVC Grid includes built-in options that show or hide columns based on the viewport width.
For a runnable example, refer to the demo on Responsive Columns for the Grid component.
- The
Hidden()configuration method takes precedence overMedia().- The
Media()configuration method cannot be used together withMinScreenWidth().
Configuration
Set the Media() configuration method of the column to a supported value. When the media query matches, the column stays visible.
@(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.Customer>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(c => c.ContactName).Media("(min-width: 450px)");
columns.Bound(c => c.ContactTitle).Width(250).Media("(min-width: 850px)");
columns.Bound(c => c.CompanyName).Width(250).Media("(min-width: 850px)");
columns.Bound(c => c.Country).Media("(min-width: 450px)");
})
.HtmlAttributes(new { style = "height: 550px;" })
.Scrollable()
.Groupable()
.Sortable()
.Pageable(pageable => pageable
.Refresh(true)
.PageSizes(true)
.ButtonCount(5))
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("Responsive_Columns_Customers_Read", "Grid"))
.PageSize(20)
)
)
Accepted Values
-
Use a valid media query string for the
matchMedia browser API. The Grid toggles column visibility based on the query result. -
Use one of the device identifiers available in Bootstrap 5:
- xs is equivalent to "(max-width: 576px)"
- sm is equivalent to "(min-width: 576px)"
- md is equivalent to "(min-width: 768px)"
- lg is equivalent to "(min-width: 992px)"
- xl is equivalent to "(min-width: 1200px)"
Column Template
Responsive Columns work with Column Templates to render multiple field values in a single compact layout.
The content in the Template() method is displayed when the Media() condition is met. For example, the following template column appears when the viewport is up to 450px wide.
@(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.Customer>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(c => c.ContactName).Media("(min-width: 450px)");
columns.Bound(c => c.ContactTitle).Width(250).Media("(min-width: 850px)");
columns.Bound(c => c.CompanyName).Width(250).Media("(min-width: 850px)");
columns.Bound(c => c.Country).Media("(min-width: 450px)");
columns.Template("#=resColTemplate(data)#").Title("Items").Media("(max-width: 450px)");
})
.HtmlAttributes(new { style = "height: 550px;" })
.Scrollable()
.Groupable()
.Sortable()
.Pageable(pageable => pageable
.Refresh(true)
.PageSizes(true)
.ButtonCount(5))
.DataSource(dataSource => dataSource
.Ajax()
.Read(read => read.Action("Responsive_Columns_Customers_Read", "Grid"))
.PageSize(20)
)
)