Click here to Skip to main content
13,352,879 members (80,970 online)
Rate this:
 
Please Sign up or sign in to vote.
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


 @(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 8-Oct-14 3:40am

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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

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 );
    }
  Permalink  
Comments
Shemeemsha RA 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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web04 | 2.8.180111.1 | Last Updated 12 Oct 2014
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100