I am attempting to use the autocomplete for incell editing. I have been searching and followed several examples but I can't get my code to work. When I select the cell, the current value deletes and the "working" spinner shows but no suggestions are listed.
Below is the code for the Grid, AutoComplete, and Controller function.
Index
@(Html.Kendo().Grid<
Timecard.Models.TimecardViewModel
>()
.Name("timecard")
.ToolBar(toolbar => toolbar.Create().Text("ADD").HtmlAttributes(new { title = "Add employee" }))
.Editable(editable => editable.Mode(GridEditMode.InCell))
.Columns(columns =>
{
columns.Bound(p => p.EmployeeName).Width(170).EditorTemplateName("_InCellAutoCompleteEditor");
columns.Bound(p => p.MonST).Filterable(false).Sortable(false).Format("{0:n1}").Title("Mon ST");
columns.Bound(p => p.MonOT).Filterable(false).Sortable(false);
columns.Bound(p => p.MonDT).Filterable(false).Sortable(false);
columns.Bound(p => p.TueST).Filterable(false).Sortable(false);
columns.Bound(p => p.TueOT).Filterable(false).Sortable(false);
columns.Bound(p => p.TueDT).Filterable(false).Sortable(false);
columns.Bound(p => p.WedST).Filterable(false).Sortable(false);
columns.Bound(p => p.WedOT).Filterable(false).Sortable(false);
columns.Bound(p => p.WedDT).Filterable(false).Sortable(false);
columns.Bound(p => p.ThuST).Filterable(false).Sortable(false);
columns.Bound(p => p.ThuOT).Filterable(false).Sortable(false);
columns.Bound(p => p.ThuDT).Filterable(false).Sortable(false);
columns.Bound(p => p.FriST).Filterable(false).Sortable(false);
columns.Bound(p => p.FriOT).Filterable(false).Sortable(false);
columns.Bound(p => p.FriDT).Filterable(false).Sortable(false);
columns.Command(command =>
{
command.Edit().UpdateText("Save");
command.Destroy().HtmlAttributes(new { title = "Delete highlighted employee" });
}).Title("Options").Width(150);
})
.Sortable()
.Scrollable()
.Filterable()
.Selectable(selectable => selectable
.Mode(GridSelectionMode.Single)
.Type(GridSelectionType.Cell)
)
.HtmlAttributes(new { style = "height:650px;width:1580px;" })
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(100)
.Model(model => model.Id(p => p.EmployeeCode))
.Read(read => read.Action("Employee_Read", "Timecard"))
.Create(create => create.Action("Employee_Create", "Employee"))
.Destroy(destroy => destroy.Action("Employee_Delete", "Employee"))
)
)
_InCellAutoCompleteEditor
@(Html.Kendo().AutoComplete()
.Name("EmployeeName")
.Filter("startswith")
.DataTextField("employeeName")
.ValuePrimitive(true)
.Placeholder("Select...")
.DataSource(source =>
{
source.Read(read =>
{
read.Action("Employee_Read", "Timecard");
})
.ServerFiltering(false);
})
)
TimecardController
public
ActionResult Employee_Read([DataSourceRequest]DataSourceRequest request)
{
DataTable dt =
new
DataTable();
using
(SqlConnection conn =
new
SqlConnection(
"Server={IPAddress};DataBase={DB};Integrated Security=SSPI"
))
{
using
(SqlCommand cmd =
new
SqlCommand())
{
cmd.CommandText =
"uspEmployeeGet"
;
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Connection = conn;
conn.Open();
dt.Load(cmd.ExecuteReader());
}
}
var dsResult = dt.ToDataSourceResult(request);
return
Json(dsResult);
}