Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
4.75/5 (3 votes)
See more:
StackOverflow Link

One of my project page contains Kendo hierarchy grid. The inner grid contain 3 combo boxes


When I select an item form 3rd combo box. A new grid row will insert below the existing row.

The problem is after adding the new row the selected values of the first 3 combo boxes are resetting..

Inner Grid Code


JavaScript
 @(Html.Kendo().Grid<Clysar.Models.HierarchyData>()
            .Name("SubGridSecuritySection")
            .Columns(columns =>
            {
                columns.Bound(o => o.Area).ClientTemplate("<input id='areaCombo_#= UserId #' >").Width("25%");
                columns.Bound(o => o.Application).ClientTemplate("<input id='applicationCombo_#= UserId #'>").Width("25%");
                columns.Bound(o => o.UserLevel).ClientTemplate("<input id='userLevelCombo_#= UserId #'>").Width("25%");
            })
            .Events(events => events.DataBound("dataBound"))
            .DataSource(dataSource => dataSource
                .Ajax()
                .PageSize(10)
                        .Read(read => read.Action("BindHierarchy", "Security"))
            )
            .Sortable()
            .ToClientTemplate()
            
    )

function dataBound() {

        this.expandRow(this.tbody.find("tr.k-master-row").first());

        var dataSourceArea = new kendo.data.DataSource({
            transport: {
                read: {
                    url: "GetAreaListForComboBox"
                }
            }
        });



        $.each($("[id^=userLevelCombo_]"), function () {
            element = this;
            $(this).kendoComboBox({
                dataSource: dataSourceUserLevel,
                dataTextField: "Value",
                dataValueField: "Key",
                filter: "contains",
                placeholder: "---Select---",
                change: function (e) {
                    debugger;
                    CreateNewGridRow();
                   
                }
               
            });
        });

    }

    function CreateNewGridRow() {
        var grid = $("#SubGridSecuritySection").data("kendoGrid");
        if (grid) {
            var dataSource = grid.dataSource;
            var total = dataSource.data().length;
            dataSource.insert(total, {});
        }
    }



How to fix this issue..?
Posted

1 solution

Get the value of combo box and set the value after inserting the new row explicitly.
i.e.

C#
function CreateNewGridRow() {
        var selectedValue = $('#comboBoxId').data('kendoComboBox').value();
        var grid = $("#SubGridSecuritySection").data("kendoGrid");
        if (grid) {
            var dataSource = grid.dataSource;
            var total = dataSource.data().length;
            dataSource.insert(total, {});
        }
       $('#comboBoxId').data('kendoComboBox').value(selectedValue );
    }
 
Share this answer
 
Comments
Shemeemsha (ഷെമീംഷ) 12-Oct-14 8:41am    
Thank you very much Satya for your answer..
It is working... (Y)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900