kendo grid inline mode selects the value of a column and automatically inserts other values of the second column into other columns

Open JS bin and enter the following code:

 

<!DOCTYPE html>

<html>

<head>

    <title>KendoUI Test Page</title>

    

    <link href="http://cdn.kendostatic.com/2013.2.716/styles/kendo.common.min.css" rel="stylesheet" />

    <link href="http://cdn.kendostatic.com/2013.2.716/styles/kendo.default.min.css" rel="stylesheet" />

    <link href="http://cdn.kendostatic.com/2013.2.716/styles/kendo.dataviz.min.css" rel="stylesheet" />

    <link href="http://cdn.kendostatic.com/2013.2.716/styles/kendo.mobile.all.min.css" rel="stylesheet" />

 

    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>

    <script src="http://cdn.kendostatic.com/2013.2.716/js/kendo.all.min.js"></script>

    <script src="http://demos.kendoui.com/content/shared/js/products.js"></script>

</head>

<body>

    <div id="grid"></div>

    <script>

 

        var dataSource = new kendo.data.DataSource({

            pageSize: 20,

            data: products,

            autoSync: true,

            schema: {

                model: {

                    id: "ProductID",

                    fields: {

                        ProductID: { editable: false, nullable: true },

                        ProductName: { validation: { required: true } },

                        Category: { defaultValue: { CategoryID: 1, CategoryName: "Beverages"} },

                        UnitPrice: { type: "number", validation: { required: true, min: 1} }

                    }

                }

            }

        });

 

        $("#grid").kendoGrid({

            dataSource: dataSource,

            pageable: true,

            height: 430,

            toolbar: ["create"],

            columns: [

            { field:"ProductName",title:"Product Name" },

            { field: "Category", title: "Category", width: "160px", editor: categoryDropDownEditor, template: "#=Category.CategoryName#" },

            { field: "UnitPrice", title:"Unit Price", format: "{0:c}", width: "120px" },

            { command: "edit", title: " ", width: "90px" }],

            editable: "inline"

        });

 

        function categoryDropDownEditor(container, options) {

            $('<input required data-text-field="CategoryName" data-value-field="CategoryID" data-bind="value:' + options.field + '"/>')

            .appendTo(container)

            .kendoDropDownList({

                //autoBind: false,

                dataSource: {

                    type: "odata",

                    transport: {

                        read: "http://demos.kendoui.com/service/Northwind.svc/Categories"

                    }

                },

                select: function(e) {

                  e.preventDefault();

                    var grid = $("#grid").data("kendoGrid"),

                        model = grid.dataItem(this.element.closest("tr"));

                  console.log(e.sender.dataSource._data[e.sender.selectedIndex]);

                    var selectedObject = e.sender.dataSource._data [e.sender.selectedIndex];

                  //model.set("ProductName",selectedObject.Description);

                    model.ProductName = selectedObject.Description;

                    model.UnitPrice = 100;

                  grid.element.find("tr[data-uid='" + model.uid + "'] td:eq(" + 0 + ")").text(selectedObject.Description);

                  grid.element.find("tr[data-uid='" + model.uid + "'] td:eq(" + 2 + ")").text(100);

                   // grid.refresh();

                  

                }

            });

        }

        </script>

</body>

</html>

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327012891&siteId=291194637