This is a migrated thread and some comments may be shown as answers.

Add new item is not sending updated model

1 Answer 181 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Howard
Top achievements
Rank 1
Howard asked on 22 Apr 2013, 06:25 AM
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.
<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>
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 

1 Answer, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 24 Apr 2013, 05:36 AM
Hi Niroj,

 
From the provided information it's not clear for us what is the exact reason for this behavior, however most probably it's related to the current editor template used for this field. Could you please provide runable project where the issue is reproduced - this would help us pinpoint the exact reason for this behavior.

Kind Regards,
Vladimir Iliev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Howard
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Share this question
or