I am using the KendoUI for ASP.NET Core in my web application. I have a custom editor for a particular column that is used when someone edits data in the grid. The grid is set to auto-sync="true"
so that the user can edit data in the cells and the changes are committed automatically.
Within the custom editor is a checkbox that I set with jQuery based on certain conditions. Even though this function works and the checkbox becomes "checked" the value the controller receives is always false
.
Here is my grid.
/Views/Home/Index
<kendo-grid name="HomePositionGrid" deferred="false">
<datasource type="DataSourceTagHelperType.Ajax" auto-sync="true">
<transport>
<read url="/Position/ReadPositions" />
<update url="/Position/UpdatePosition" />
</transport>
<schema>
<model id="Id">
<fields>
<field name="Id" editable="false" />
</fields>
</model>
</schema>
</datasource>
<editable mode="incell" />
<columns>
<column field="Name" title="Name" />
<column field="ExpectedOffhire" editor="expectedOffhireEditor" title="ExpectedOffhire" />
</columns>
</kendo-grid>
As you can see it's a tag helper grid with auto-sync
set to true
and a custom editor of expectedOffhireEditor
defined.
Here is that editor
wwwroot/js/expectedOffhireEditor
function expectedOffhireEditor(container, options) {
$('<input name="' + options.field + '" id="' + options.field + '" />')
.appendTo(container)
.kendoDateTimePicker({
valuePrimitive: true
});
$('<input name="PPT" id="PPT" />')
.appendTo(container)
.kendoDropDownList({
dataTextField: "text",
dataValueField: "value",
optionLabel: "-- Select --",
change: setPromptDate,
dataSource: [
{
value: 1,
text: "Prompt"
},
{
value: 2,
text: "Prompt AM"
},
{
value: 3,
text: "Prompt PM"
}
]
});
$('<input type="checkbox" id="Prompt" name="Prompt" for="Prompt" />').appendTo(container)
}
There are three inputs created here, the first is a DateTime picker, the second is a dropdown list and the third is a basic checkbox. When the user selects an option from the dropdown list, it must set the checkbox to checked
which is handled by the change event called setPromptDate
.
setPromptDate
function setPromptDate(e) {
$('#Prompt').prop("checked", true);
//shortened for brevity ...
}
When the data is posted from the grid and reaches the controller, the value of the checkbox is always false
I've tried various ways of doing it but prompt
checkbox is just not posting. If I check the box myself using the mouse, the value will post as"true", it's something to do with setting the checked status with jquery that isn't playing well.
Has anyone encountered this before who can shed some light on what is wrong?