The Kendo UI Grid's Toolbar Template UI for ASP.NET MVC documentation displays an approach used for UI for ASP.NET Core. The ClientTemplate and ClientTemplateID are not available for UI for ASP.NET MVC.
Please try the approach used in the documentation. It is not available for UI for ASP.NET MVC.
Either include the approach for UI for ASP.NET MVC, or modify the documentation.
https://demos.telerik.com/aspnet-mvc/grid/right-to-left-support
https://demos.telerik.com/kendo-ui/grid/right-to-left-support
https://demos.telerik.com/aspnet-core/grid/right-to-left-support
Incorrect rendering of the buttons.
Buttons rendered consistently with the jQuery and Core Grids.
A hidden template column that is not included in the ColumnMenu appears after showing another column
.Columns(columns =>
{
//Hidden template column
columns.Template(x =>
{
int rptIndex = Model.IndexOf(x);
string namePrefix = "Grid[" + rptIndex + "].";
Html.Hidden(namePrefix + "Id", x.Id, new { @readonly = "readonly" });
Html.Hidden(namePrefix + "Name", x.Name, new { @readonly = "readonly" });
}).Hidden().IncludeInMenu(false);
columns.Bound(x => x.Id).Width(120).Hidden(true);
columns.Bound(x => x.Name).Width(200);
columns.Bound(x => x.ReportingDateOriginal).Width(500).HtmlAttributes(new { id = "reporting-date-original" })
.Filterable(f => f.UI(GridFilterUIRole.DateTimePicker).Cell(c => c.Template("dateFilter")));
columns.Bound(x => x.Test1).Width(200).Hidden(true);
columns.Bound(x => x.TimezoneOffset).Width(200).HtmlAttributes(new { id = "reporting-date-offset" });
columns.Bound(x => x.Test2).Width(200).Hidden(true);
columns.Bound(x => x.ReportingDateAdjusted).Width(500).HtmlAttributes(new { id = "reporting-date-adjusted" })
.Filterable(f => f.UI(GridFilterUIRole.DateTimePicker).Cell(c => c.Template("dateFilter")));
columns.Bound(x => x.Test3).Width(200);
columns.Bound(x => x.Test4).Width(200).Hidden(true);
columns.Bound(x => x.Test5).Width(200);
})
The first time instead of the Id, the template column appears.
The Id column should appear and the template column should remain hidden.
When using template and no DataSource is set Grid NoRecords message is not rendered.
Define a 'No Records' with template similar to the following article example: https://docs.telerik.com/aspnet-mvc/html-helpers/data-management/grid/templates/no-records
@(Html.Kendo().Grid<Grid_Template.Controllers.GridModel>()
.Name("Grid1")
.NoRecords(n => n.Template("string HTML template, not centered"))
)
The default message for missing record is displayed: No records available.
"autoBind":false is applied to serialization
The message from the template is displayed: "string HTML template, not centered"
Workaround:
Add .DataSource(d => d.Ajax()) to the Grid configuration
@(Html.Kendo().Grid<Grid_Template.Controllers.GridModel>()
.Name("Grid1")
.NoRecords(n => n.Template("string HTML template, not centered"))
.DataSource(d => d.Ajax())
)
https://github.com/telerik/kendo-ui-core/issues/6598
I would like to be able to create .bindBoolColumn. I do not want extend the column itself. I already have extensions for that.
Something like this:
GridBoundColumnBuilder<TModel> BoundBoolean<TValue>(Expression<Func<TModel, TValue>> expression)
public GridBoundColumnBuilder<TModel> BoundBool<TValue>(Expression<Func<TModel, TValue>> expression)
{
column = *place create column code here*;
column.Width(90);
column.clientTemplate("customtemplate");
}
Currently the ForeignKey column expects data to be loaded in it initially. This could be either local data or remote data.
For scenarios that involve using large data, it would be helpful if we can have more flexibility with the way data is loaded in the column's editor (e.g., DropDownList). For example, we want to use cascading ForeignKey editors. Once a selection is made in the first dropdown, the second cascades and is loaded with the respective data. This is not viable at the moment, because the data must be supplied to the ForeignKey column initially. If an empty collection is passed initially:
columns.ForeignKey(c => c.Field1, new List<SelectListItem>(), "Value", "Text").Width(100);
and the dropdown is then loaded with data after the Grid's Edit popup opens, the ForeignKey column will display the DataFieldValue as text, because no initial data has been provided.
An option to load data on demand would be a welcome performance enhancement.
add a grid to a view
open the view with data bound to the grid.
First line of data is not selected.
Now i have to program the ondatabound property for a function which belongs to the grid component. Make it configurable for grids which do not need this feature or vice versa.
Hi,
I'm experiencing a bug with the kendo grid. In my project I have a rather complicated website where a kendo grid is loaded depending an multiple criteria which can be chosen by the user through dropdowns and multiselects. Luckily, I could break it down to a simple test website and the bug still is bugging around ;)
Description: Depending on the criteria chosen, the grid loads different data which reach from zero to thousands of data rows. In my example here, it's either zero or 100 data rows (depending on the dropdown, if there is either "Empty" or "Not empty" selected). The grid loads its data if you press the button ok (by calling the Load action on the server). The result is meant to be limited to paging of 25 rows (no user choice wanted)!
Heres the code for the cshtml site:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<div id="content">
<div>
@(Html.Kendo().DropDownList()
.Name("test_selector")
.DataTextField("Display")
.DataValueField("Value")
.BindTo(new List<DropDownVM>() {
new DropDownVM() {
Display = "Empty",
Value = "empty"
},
new DropDownVM() {
Display = "Not empty",
Value = "notEmpty"
}
})
)
</div>
<div>
@(Html.Kendo().Grid<MyProject.ViewModels.Test.TestItem>()
.Name("grid_Test")
.Columns(columns =>
{
columns.Bound(x => x.TestId).Title("TestId").Width(75);
columns.Bound(x => x.TestName).Title("TestName").Width(75);
})
.Sortable()
.Pageable()
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(25)
.Read(read => read.Action("Load", "Test").Data("GetSelectorData"))
)
.AutoBind(false) //Do not load Grid data initially
)
</div>
<div>
@Html.Kendo().Button().Name("Load").Content("Load")
</div>
</div>
<script type="text/javascript">
$("#Load").on("click", function (e) {
var grid = $("#grid_Test");
grid.data("kendoGrid").dataSource.read();
});
function GetSelectorData() {
var selectorData = {
type: $('#test_selector').data("kendoDropDownList").value()
}
return selectorData;
}
</script>
</body>
</html>
And the corresponding controller:
public class TestController : BaseController
{
public ActionResult Index()
{
return View();
}
public ActionResult Load([DataSourceRequest] DataSourceRequest request, string type)
{
List<TestItem> result = new List<TestItem>();
if (type == "notEmpty")
{
for (int id = 1; id <= 100; id++)
result.Add(CreateTestItem(id));
}
request.PageSize = 25;
return Json(result.ToDataSourceResult(request));
}
private TestItem CreateTestItem(int id)
{
TestItem result = new TestItem()
{
TestId = id,
TestName = "Name" + id
};
return result;
}
}
Problem: The scenario described above works actually fine as long as the
grid gets at least one data row delivered as DataSourceResult (i.e., result.Count > 0 in the Load method of the controller). The request object in the
controller's Load method also shows request.PageSize to be configured to 25. Also, if I choose "Empty" from the dropdown and press the Load-button, the request in the controller will show PageSize = 25. But if I switch the selector to "Not empty" afterwards and press Load, the request will show PageSize = 0! This results in the grid not being paged at all and showing all results on a single page (which leads to serious connectivity problems in my productive project as soon as there are several thousands of data rows).
I tried a quick workaround in the Load method of the controller by setting the PageSize manually back to 25 (which is not wanted of course, but would actually work for me at the moment):
public ActionResult Load([DataSourceRequest] DataSourceRequest request, string type)
{
List<TestItem> result = new List<TestItem>();
if (type == "notEmpty")
{
for (int id = 1; id <= 100; id++)
result.Add(CreateTestItem(id));
}
request.PageSize = 25;
return Json(result.ToDataSourceResult(request));
}
Unfortunately, this doesn't work either. The paging will be back on again and there will be only 25 data rows loaded in the grid but there is only one single page no matter how many data rows are loaded (see attached screenshot).
Do you know about this? Unfortunately I couldn't find any help for this problem so far.
Greetings!
Using server binding does not render the NoRecords message for the Grid
@(Html.Kendo().Grid(new List<Product>())
.Name("Grid")
.Columns(columns => {
columns.Bound(p => p.ProductID).Groupable(false);
columns.Bound(p => p.ProductName);
columns.Bound(p => p.UnitPrice);
columns.Bound(p => p.UnitsInStock);
})
.NoRecords("No records found.")
.Pageable()
.Sortable()
.Scrollable()
.DataSource(d=>d.Server())
.Filterable()
.Groupable()
)
A possible workaround is to use local binding by setting the AJAX binding in the DataSource, but keep the initial server binding:
@(Html.Kendo().Grid(new List<Product>())
.Name("Grid")
.Columns(columns => {
columns.Bound(p => p.ProductID).Groupable(false);
columns.Bound(p => p.ProductName);
columns.Bound(p => p.UnitPrice);
columns.Bound(p => p.UnitsInStock);
})
.NoRecords("No records found.")
.Pageable()
.Sortable()
.Scrollable()
.DataSource(d=>d.Ajax().ServerOperation(false))
.Filterable()
.Groupable()
)
It would be nice, if you can create a build-in property or function to create icon-only buttons/commands in a grid.
Actually it requires some workaround to realize this.
This Example create an edit button with the k-button-icontext class, but i want only an k-button-icon button. The destroy button gets the button name as default text.
@(Html.Kendo().Grid<WidgetDashboard.Models.Widget.WidgetData>()
.Name("adminWidgetGrid")
.Columns(columns =>
{
columns.Bound(p => p.Name).Width(150);
columns.Bound(p => p.Active).Width(75);
columns.Command(command => { command.Edit().Text(" "); command.Destroy().Text(""); }).Width(300);
})
//.ToolBar(toolbar => toolbar.Create())
.Editable(editable => editable.Mode(GridEditMode.InLine))
.Pageable(p => p.Refresh(true))
.Sortable()
.Scrollable()
.Resizable(r => r.Columns(true))
.HtmlAttributes(new { style = "height:450px; width: 100%" })
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
//.Events(events => events.Error("error_handler"))
.Model(model => model.Id(p => p.ID))
.Create(update => update.Action("Admin_Create", "Dashboard", new { id = Model.DashboardId }))
.Read(read => read.Action("Admin_Read", "Dashboard", new { id = Model.DashboardId }))
.Update(update => update.Action("Admin_Update", "Dashboard", new { id = Model.DashboardId }))
.Destroy(update => update.Action("Admin_Destroy", "Dashboard", new { id = Model.DashboardId }))
)
)
Alternative it would be ok if the correct css class is given when an empty string is specified.
Thank you
Christian
I've been using the "Change" event to handle a Single Row Selection grid as that seems to be the event to use to determine when the user selects a row.
I just tried adding "persistSelection(true)" to my grid but it seems to be triggering a change event when I switch to another page and back to the previous page, or do an external $(this).data('kendoGrid').dataSource.read() on the grid.
How can I only get a change event when the USER selects a row, not the persistedSelection selecting the row?
Or at least detetect where it came from it in my Change event?
Thanks,
Bryan
Hello,
since I updated Telerik UI for ASP.net MVC from version 2019.1.220 to 2019.2.514, the paging part of the grid doesn't display as expected in IE11 with compatibility with IE9 (<meta http-equiv="x-ua-compatible" content="IE=9">)
If I remove the compatibility with IE9, it's ok, but I need it to support older computer.
version 2019.1.220:
version 2019.2.514:
Is there a solution to display it correctly?
Thank you very much and best regards.
Emmanuel Tharin
Hey,
I might have found another bug.
The "Change" Event isn't triggered for checkboxes if GroupPaging is set to true.
If it's disabled, the event gets caught as expected.
Html.Kendo().Grid<PlotWhitelistViewModel>()
.Name("whitelistGrid")
.Columns(c =>
{
c.Bound(x => x.Id).Hidden();
c.Select().Width(50);
c.Bound(x => x.ArticleNo);
})
.Events(x =>
{
x.Change("onWhitelistGridChange");
})
.Scrollable(s => s.Virtual(true))
.DataSource(dataSource => dataSource
.Ajax()
.Group(x => x.Add(y => y.ArticleGroup))
.GroupPaging(true)
.PageSize(50)
.Read("GridRead_Whitelist", "Plot", new {plotId = Model})
.Model(m =>
{
m.Id(f => f.Id);
m.Field(f => f.ArticleNo);
m.Field(f => f.ArticleGroup);
m.Field(f => f.IsChecked);
}))
Regards
Nils
Aligning numeric values in grids is common place and best practise. Kendo Grid does not provide any neat functionality for this, especially in MVC where the model is strongly typed. Where a MVC grid is bound to a model, the Razor Wrapper would work better if it right aligned columns if for example type int (or other numeric types which are better to be right aligned). Where this needs not to be the case a data annotation would suit.
eg.
public class MyModel
{
[AlignRight(false)]
public int ProductID {get; set;}
public int Age {get; set; } // aligned right by default in Kendo Grid because of int type
}
In the above case ProductID would be left aligned, and Age would be right (which could be the default for all integer types)
With this functionality the razor implementation could also provide an align property to override align functionality. An AutoAlign property could provide this functionalityto auto detect from model or not (and also allow this functionality as being off to provide backwards compatibility)
@(Html.Kendo().Grid<MyModel>()
.Name("grid")
.AutoAlign(false)
.Columns(columns =>
{
columns.Bound(c => c.ProductID).AlignRight(false)
columns.Bound(c => c.Age).AlignRight(True)
})