Click here to Skip to main content
14,640,670 members

Add a row to kendo grid programmatically without grid refresh

Shemeemsha (ഷെമീംഷ) asked:

Open original thread
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..?
Tags: MVC, Telerik, Kendo

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).




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