Hi Kendo Team,
I've a grid that have one ajax call to get the description and display in the grid and also there are two auto increment columns. The problem I'm having with it is when I'm adding a new record, the model is not updated when sending to the controller. This is my view page.
If you see my attached screenshot, you will be able to see the discrepancies.
Please let me know, how can I fix this.
Thank you
I've a grid that have one ajax call to get the description and display in the grid and also there are two auto increment columns. The problem I'm having with it is when I'm adding a new record, the model is not updated when sending to the controller. This is my view page.
<
script
type
=
"text/javascript"
>
function onWorkshopJobRequirementListRequestEnd(e) {
if (e.type == "create" || e.type == "update") {
e.sender.read();
}
}
function onWorkshopJobRequirementListError(e) {
if (e.errors) {
var message = "Errors:\n";
$.each(e.errors, function (key, value) {
if (value.errors) {
message += value.errors.join("\n");
}
});
alert(message);
}
}
function JobRequirementList_Edit(e) {
e.sender.showColumn("REQUIREMENT_DESCRIPTION_CUSTOM");
e.container.find("input[name=SEQUENCE]").css('width', '80px');
if (e.model.isNew()) {
debugger
e.container.find("input[name=SEQUENCE]").val(++currentSequence);
e.container.find("input[name=LINE_NUMBER]").val(++currentLineNo);
}
e.container.find(".k-grid-cancel").bind("click", function () {
e.sender.hideColumn("REQUIREMENT_DESCRIPTION_CUSTOM");
})
}
function JobRequirementList_Databound(e) {
e.sender.hideColumn("REQUIREMENT_DESCRIPTION_CUSTOM");
}
function Requirement_change(e) {
$.ajax({
url: "@Url.Action("GetRequirementDescription", "Shared")",
data: {requirementId: e.sender.value()},
datatype: "json",
type: "POST",
success: function(myData){
$("#REQUIREMENT_DESCRIPTION_CUSTOM").attr('value', myData);
}
});
}
</
script
>
@(Html.Kendo().Grid<
WorkshopJobRequirement
>()
.Name("WorkshopJobRequirementList_" + ViewData["WorkshopJobId"])
.Sortable()
.Pageable(paging =>
{
//paging.Messages(message => message.Display("Total standard hours: " + ViewData["TotalTime"].ToString()));
paging.Enabled(true);
paging.Info(true);
paging.PageSizes(true);
paging.Numeric(true);
paging.PreviousNext(true);
paging.Refresh(true);
paging.PageSizes(new int[5] { 5, 10, 15, 20, 25 });
})
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(15)
.Model(model =>
{
model.Id(p => p.REQUIREMENT_TRANS_ID);
model.Field(p => p.WORKSHOP_TRANSACTION_ID).DefaultValue((int)ViewData["WorkshopJobId"]);
model.Field(p => p.LINE_NUMBER).Editable(false).DefaultValue((short)ViewData["MaxLineNo"]);
model.Field(p => p.SEQUENCE).DefaultValue((short)ViewData["MaxSequence"]);
model.Field(p => p.STANDARD_HOURS).Editable(false);
})
.Events(events =>
{
events.RequestEnd("onWorkshopJobRequirementListRequestEnd");
events.Error("onWorkshopJobRequirementListError");
})
.Read(read => read.Action("_WorkshopJobRequirementList", "RepairAndMaintenanceJobRequirementList", new { workshopJobId = ViewData["WorkshopJobId"] }))
.Update(update => update.Action("_WorkshopJobRequirementEdit", "RepairAndMaintenanceJobRequirementList"))
.Create(create => create.Action("_WorkshopJobRequirementCreate", "RepairAndMaintenanceJobRequirementList"))
)
.Selectable(selectable => selectable.Mode(GridSelectionMode.Single))
.ToolBar(toolbar => toolbar.Create())
.Reorderable(reorder => reorder.Columns(true))
.Filterable()
.Columns(columns =>
{
columns.Bound(p => p.LINE_NUMBER).Title("Line no").Width("80px");
columns.Bound(p => p.SEQUENCE).Title("Sequence").Width("80px");
if (Model.DISPLAY_MM_HOURS_REQUIREMENTS)
{
columns.Bound(p => p.STANDARD_HOURS).Title("Std hours").Width("80px");
//.FooterTemplate("Total standard hours: " + ViewData["TotalTime"].ToString());
}
columns.Bound(p => p.REQUIREMENT_ID).Title("Requirement").EditorTemplateName("_Requirement")
.ClientTemplate("#=REQUIREMENT_DESCRIPTION_CUSTOM#");
columns.Bound(p => p.REQUIREMENT_DESCRIPTION_CUSTOM).Title("Description");
columns.Bound(p => p.PRINT_FLAG).Title("Print")
.Width("80px").HtmlAttributes(new { @style = "text-align:center" })
.ClientTemplate("<
input
type
=
'checkbox'
disabled
=
'disabled'
name
=
'suppressed'
#=PRINT_FLAG?
checked
=
'checked'
:''# />");
columns.Bound(p => p.COMPLETE).Title("Complete")
.Width("80px").HtmlAttributes(new { @style = "text-align:center" })
.ClientTemplate("<
input
type
=
'checkbox'
disabled
=
'disabled'
name
=
'suppressed'
#=COMPLETE?
checked
=
'checked'
:''# />");
columns.Command(command =>
{
command.Edit();
}).Width(200).Title("Commands").HeaderHtmlAttributes(new { @style = "text-align:center" });
})
.Events(events => events.Edit("JobRequirementList_Edit").DataBound("JobRequirementList_Databound"))
)
<
script
type
=
"text/javascript"
>
var currentSequence;
var currentLineNo;
$(function () {
$('#WorkshopJobRequirementList_@ViewData["WorkshopJobId"]').data("kendoGrid").one("dataBound", function (e) {
currentSequence = e.sender.dataSource.options.schema.model.fields.SEQUENCE.defaultValue;
currentLineNo = e.sender.dataSource.options.schema.model.fields.LINE_NUMBER.defaultValue;
})
})
</
script
>
Please let me know, how can I fix this.
Thank you