Custom grid incell editing

1 Answer 43 Views
Grid
Avinash
Top achievements
Rank 1
Avinash asked on 21 Nov 2024, 11:35 AM | edited on 21 Nov 2024, 11:38 AM
public class ListMasterBOQResourceCalc
{
    public Nullable<int> BOQId { get; set; }
    public int AutoID { get; set; }
    public Nullable<int> RsrcTypeID { get; set; }
    public int raRsrcID { get; set; }
    public Nullable<decimal> rsrcQty { get; set; }
    public Nullable<decimal> wastagePct { get; set; }
    public Nullable<int> DisciplineID { get; set; }
    public string raRsrcName { get; set; }
    public string Unit { get; set; }
    public Nullable<decimal> BaseRate { get; set; }
    public string TotalQty { get; set; }
    public string TotalRate { get; set; }

    [Required]
    [UIHint("ClientResource")]
    public ResourceTypeModel RsrcType { get; set; }

    [Required]
    [UIHint("ClientSubResources")]
    public DrpResourceModel drpResource { get; set; }

}

 

@(Html.Kendo().Grid<RVNLMIS.Models.ListMasterBOQResourceCalc>()
        .Name("ResourceTypeGrid")
        .Columns(columns =>
        {

            // Resource Type column
            columns.Bound(c => c.RsrcType)
                .Title("Resource Type")
                .ClientTemplate("#= RsrcType ? RsrcType.ResourceTypeName : '' #")
                .EditorTemplateName("ClientResource")
                .Sortable(false)
                .HtmlAttributes(new { style = "text-align:left" })
                .HeaderHtmlAttributes(new { style = "text-align:left" })
                .Width(120)
                ;

            // Resource Name column
            columns.Bound(c => c.drpResource)
                .Title("Resource")
                .ClientTemplate("#= drpResource ? drpResource.ResourceName : ''#")
                .EditorTemplateName("ClientSubResources")
                .Sortable(false)
                .HtmlAttributes(new { style = "text-align:left" })
                .HeaderHtmlAttributes(new { style = "text-align:left" })
                .Width(120);

            // Quantity column
            columns.Bound(c => c.rsrcQty)
                .Title("Quantity")
                .HtmlAttributes(new { style = "text-align:right" })
                .HeaderHtmlAttributes(new { style = "text-align:right" })
                .Width(70)
                .Format("{0:N2}");

            // Wastage Percentage column
            columns.Bound(c => c.wastagePct)
                .Title("Wastage %")
                .HtmlAttributes(new { style = "text-align:right" })
                .HeaderHtmlAttributes(new { style = "text-align:right" })
                .Width(60);

            // Total Quantity column
            columns.Bound(c => c.TotalQty)
                .Title("Total Qty")
                .HtmlAttributes(new { style = "text-align:right" })
                .HeaderHtmlAttributes(new { style = "text-align:right" })
                .Width(80)
                .Format("{0:N2}");

            // Unit column
            columns.Bound(c => c.Unit)
                .Title("Unit")
                .HtmlAttributes(new { style = "text-align:left" })
                .HeaderHtmlAttributes(new { style = "text-align:left" })
                .Width(60);

            // Base Rate column
            columns.Bound(c => c.BaseRate)
                .Title("Base Rate")
                .HtmlAttributes(new { style = "text-align:right" })
                .HeaderHtmlAttributes(new { style = "text-align:right" })
                .Width(80)
                .Format("{0:N2}");

            // Total Rate column
            columns.Bound(c => c.TotalRate)
                .Title("Resource Amount")
                .HtmlAttributes(new { style = "text-align:right" })
                .HeaderHtmlAttributes(new { style = "text-align:right" })
                .Width(100)
                .Format("{0:N2}");
            columns.Command(command => command.Destroy()).Width(150);
        })
        .ToolBar(toolBar =>
        {
            toolBar.Create(); // Adds a Create button
            toolBar.Save();   // Adds a Save button
        })
        .Editable(editable => editable.Mode(GridEditMode.InCell))
        .Pageable() // Pagination enabled
        .Sortable() // Sorting enabled
        .Scrollable() // Scrollable grid
        .HtmlAttributes(new { style = "height:550px;" })
        .DataSource(dataSource => dataSource
            .Ajax()
            .Batch(true) // Batch editing
            .ServerOperation(false) // Client-side operations
            .Model(model =>
            {
                model.Id(p => p.AutoID); // Set primary key
                model.Field(p => p.AutoID).Editable(false); // Disable editing for AutoID
                model.Field(p => p.RsrcType).DefaultValue(
                            ViewData["defaultResourceType"] as RVNLMIS.Controllers.Sub_BOQController.ResourceTypeModel);
                model.Field(p => p.drpResource).DefaultValue(new RVNLMIS.Controllers.Sub_BOQController.DrpResourceModel
                {
                    ResourceName = "Select Resource",
                    ResourceID = 0
                });
            })
            .PageSize(20) // Set page size
            .Read(read => read.Action("GetBOQResource_Details", "Sub_BOQ").Data("getBOQId"))
            .Create(create => create.Action("EditingCustom_Create", "Sub_BOQ"))
            .Update(update => update.Action("EditingCustom_Update", "Sub_BOQ"))
            .Destroy(destroy => destroy.Action("EditingCustom_Destroy", "Sub_BOQ"))
        )
     )

ClientResource.cshtml

public class ResourceTypeModel
{
    public int ResourceTypeId { get; set; }
    public string ResourceTypeName { get; set; }
}

@model RVNLMIS.Controllers.Sub_BOQController.ResourceTypeModel

@(Html.Kendo().DropDownListFor(m => m)
    .Name("drpRsrcTypeId")
    .OptionLabel("Select Resource Type")
        .DataValueField("ResourceTypeId")
        .DataTextField("ResourceTypeName")
        .BindTo((IEnumerable<RVNLMIS.Controllers.Sub_BOQController.ResourceTypeModel>)ViewData["listResourceTypes"])
        .Events(e => e.Change("onResourceTypeChange"))
)

ClientSubResources.cshtml

public class DrpResourceModel
{
    public int ResourceID { get; set; }
    public string ResourceName { get; set; }
}

@model RVNLMIS.Controllers.Sub_BOQController.DrpResourceModel


@(Html.Kendo().DropDownListFor(m => m)
    .Name("drpRsrcId")
    .OptionLabel("Select Resource")
    .DataTextField("raRsrcName")
    .DataValueField("raRsrcID")
    .CascadeFrom("drpRsrcTypeId") // Cascade from the Category dropdown
    .DataSource(dataSource => dataSource
        .Read(read => read.Action("GetResourcesByTypeId", "Sub_BOQ").Data("getRsrcTypeID")) // Action to fetch subcategories
    )
    .Events(e => e.Change("onResourceChange"))
)

 

After selecting the values from dropdown , the values are not remain selected & also not passing to create method. The default values are passing to create method.

 

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 21 Nov 2024, 12:50 PM

Hello ,

 

I have gone through the code snippets and your code seems correct.

I have provided the link to the working project for this scenario in the other forum thread, but sharing it here for visibility as well:
https://github.com/telerik/ui-for-aspnet-mvc-examples/tree/master/Telerik.Examples.Mvc/Telerik.Examples.Mvc/Areas/GridEditingInCellCascadingDropDownLists

Please use it as a reference base and compare it with your original project.

Also, run the page on Chrome browser and enable the F12 inspector console to see if there are script errors interfering.

 

Regards,
Eyup
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Avinash
Top achievements
Rank 1
commented on 22 Nov 2024, 06:58 AM

Thanks for you comment , got issue resolved.
Tags
Grid
Asked by
Avinash
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or