I am facing an issue with the grid I have set up, which includes multiple columns such as Id(integer)
and Name(string)
. The change event is functioning properly for the Name column, but not for the ID column.
I would like this functionality to be implemented on the server side using Razor syntax.
As a newcomer to Kendo UI, any guidance on how to accomplish this would be greatly appreciated.
Below is the code snippet I am currently using:
@(Html.Kendo().Grid(Model).Name("ViewDataGrid")
.Columns(columns =>
{
columns.Bound(c => c.Id).Title(" ID").Width(150);
columns.Bound(c => c.Name).Title(" Name").Width(150);
})
.HtmlAttributes(new { style = "height: auto; width: 2200px" })
.Filterable(i => i.Mode(GridFilterMode.Menu | GridFilterMode.Row))
.Sortable(s => s.AllowUnsort(false).SortMode(GridSortMode.MultipleColumn))
.Selectable(selecting => selecting.Enabled(true))
.Pageable(r => r.PreviousNext(true).PageSizes(new int[] { 10, 20, 30, 40, 50, 100 }))
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.ServerOperation(false)
.Events(e => e.Change("call"))
))
function call(e) {
if (e.sender.filter.arguments[0].filters != null) {
if (e.sender.filter.arguments[0].filters[0].value == "") {
$('#ViewDataGrid').data('kendoGrid').dataSource.filter({});
}
else {
var filterlength = e.sender.filter.arguments[0].filters.length;
$filter = new Array();
if (e.sender.filter.arguments[0].filters[0].field == "Id")
$filter.push({ field: e.sender.filter.arguments[0].filters[0].field, operator: "eq", value: e.sender.filter.arguments[0].filters[0].value });
else
$filter.push({ field: e.sender.filter.arguments[0].filters[0].field, operator: "contains", value: e.sender.filter.arguments[0].filters[0].value });
$("#ViewDataGrid").data("kendoGrid").dataSource.filter($filter);
}
}
}
Model.CS
public int Id { get; set; }
public string Name { get; set; }
Controller
public ActionResult Index()
{
List<GridData> dataList = new List<GridData>();
GridData data1 = new GridData();
data1.Id = 9191919;
data1.Name = "XYZ";
dataList.Add(data1);
return View(dataList);
}