首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Kendo网格:如何在“添加新行”而不是“编辑”上创建执行某些获取

Kendo网格:如何在“添加新行”而不是“编辑”上创建执行某些获取
EN

Stack Overflow用户
提问于 2017-08-31 07:12:07
回答 3查看 279关注 0票数 1

在我的KendoGrid中,我想在弹出表单中添加输入字段的默认值.

我已经创建了一个函数,我打算在单击Create按钮时调用该函数,但下面的函数不起作用。我找了很多,但没有找到任何帮助,所以如果有人能告诉我问题出在哪里,那就太好了。

代码语言:javascript
运行
复制
 function add_m(e) {
    debugger;
    $("#DeviceIP").val("123");
}
$("#turbingrid").kendoGrid({
     //   debugger;

     dataSource: dataSource,
     scrollable: false,
     //toolbar: ["create"],
     toolbar: [
                  {name: "create",text: "add new turbine"}
              ],
     columns: [
                  { field: 'DeviceIP', title: 'DeviceIP', width: '100px', id: 'DeviceIP' },
                  { field: 'Producer', title: 'Producer', width: '80px', id:'Producer'},//editor: ProductNameDropDownEditor,
                  { field: 'Model', title: 'Model', width: '220px',id:'Model' },
                  { field: 'DeviceType', title: 'DeviceType', width: '100px', editor: deviceTypesList },
                  { field: 'Description', title: 'Description', width: '220px' },
                  { field: 'Username', title: 'Username', width: '120px' },
                  { field: 'Password', title: 'Password', width: '100px' },
                  { field: 'PublicIP', title: 'PublicIP', width: '120px' },
                  { field: 'TurbineId', title: 'TurbineId', width: '120px', hidden: true },
                  { field: 'device_id', title: 'device_id', width: '120px', hidden: true },
                  { field: 'ModelProducer', title: 'Producer/Model', hidden: true, editor: modelProducer },
                  {command: ["edit"], title: " "}
             ],
        //{
        //    command: [
        //                 {
        //                     name: "Edit",
        //                     click: function (e) {
        //                             temp = $(e.target).closest("tr"); //get the row
        //                     }
        //                 }
        //             ]
        //}


     editable: "popup",
     create:add_m,
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2017-08-31 07:53:58

要动态分配val或属性,请使用

编辑

代码语言:javascript
运行
复制
edit: function(e) {
    if (e.model.isNew()) {
       e.container.find("input[name=test]").val(5555); // name changed, but worked for me
      // e.container.find("input[name=device_id]").val(123);
    }
}

beforeEdit

代码语言:javascript
运行
复制
beforeEdit: function(e) {
    if (e.model.isNew()) {
      $("#DeviceIP").val("123");
    }
}
票数 0
EN

Stack Overflow用户

发布于 2017-08-31 08:34:29

您可以使用beforeEdit事件,而不是create事件。当在工具栏中单击create按钮时,它将触发。

票数 0
EN

Stack Overflow用户

发布于 2017-08-31 12:08:47

这是工作的演示

下面是粘贴DeviceIPAdd row event上的默认值的代码片段。

代码语言:javascript
运行
复制
$("#turbingrid").kendoGrid({
....
.........
//ON CLICK ADD/EDIT BUTTON FOR PRODUCT ITEM
        edit: function(e) {

            // CHANGE ADD/EDIT PRODUCTITEM POPUP FORM TITLE
            if (e.model.isNew()) //ON ADD NEW
            {
                $(".k-window-title").text("Add New Turbine");
                // HERE e.container IS THE ADD/EDIT POPUP FORM ELEMENT
                e.container
                    .find("[name=DeviceIP]") // get the span element for the field
                    .val("123") // set the value
                .change(); // trigger change in order to notify the model binding

            } 
            else // ON EDIT
            {
                $(".k-window-title").text("Edit Turbine");
            }
        }
........
....
});

这是演示小提琴的完整代码。

代码语言:javascript
运行
复制
(function () {



      var dataSource = new kendo.data.DataSource({
            data: {
                id: 1,
                DeviceIP: "192.168.1.1",
                Producer: 'Producer',
                Model: 'Model',
                DeviceType: 'DeviceType',
                Description: 'Description',
                Username: 'Username',
                Password: 'Password',
                PublicIP: '216.168.123.156',
                TurbineId: 1,
                device_id: 2,
                ModelProducer: 'ModelProducer',
            },
            schema: {
                model: {
                    id: 'id',
                    fields: {
                        DeviceIP: {},
                        Producer: {},
                        Model: {},
                        DeviceType: {},
                        Description: {},
                        Username: {},
                        Password: {},
                        PublicIP: {},
                        TurbineId: {},
                        device_id: {},
                        ModelProducer: {},

                    }
                }
            }
        });


    $('#grid').kendoGrid({
     dataSource: dataSource,
     scrollable: false,
     //toolbar: ["create"],
     toolbar: [
                  {name: "create",text: "add new turbine"}
              ],
     columns: [
                  { field: 'DeviceIP', title: 'DeviceIP', width: '100px', id: 'DeviceIP' },
                  { field: 'Producer', title: 'Producer', width: '80px', id:'Producer'},//editor: ProductNameDropDownEditor,
                  { field: 'Model', title: 'Model', width: '220px',id:'Model' },
                  { field: 'DeviceType', title: 'DeviceType', width: '100px' },
                  { field: 'Description', title: 'Description', width: '220px' },
                  { field: 'Username', title: 'Username', width: '120px' },
                  { field: 'Password', title: 'Password', width: '100px' },
                  { field: 'PublicIP', title: 'PublicIP', width: '120px' },
                  { field: 'TurbineId', title: 'TurbineId', width: '120px', hidden: true },
                  { field: 'device_id', title: 'device_id', width: '120px', hidden: true },
                  { field: 'ModelProducer', title: 'Producer/Model', hidden: true },
                  {command: ["edit"], title: " "}
             ],
        editable: 'popup',
        //ON CLICK ADD/EDIT BUTTON FOR PRODUCT ITEM
        edit: function(e) {

            // CHANGE ADD/EDIT PRODUCTITEM POPUP FORM TITLE
            if (e.model.isNew()) //ON ADD NEW
            {
                $(".k-window-title").text("Add New Turbine");
                // HERE e.container IS THE ADD/EDIT POPUP FORM ELEMENT
                e.container
                    .find("[name=DeviceIP]") // get the span element for the field
                    .val("123") // set the value
                .change(); // trigger change in order to notify the model binding

            } 
            else // ON EDIT
            {
                $(".k-window-title").text("Edit Turbine");
            }
        }
    });
})()
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45975396

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档