louhanbao1 2017-01-10 07:35 采纳率: 0%
浏览 3989
已结题

kendo ui grid里有一列是上传控件upload,grid增加行addrow,如下图

   <div class="content-grid" data-options="region:'center',border:false">
        <div id="processDetailGrid"></div>

    </div>
 $(function () {
        ProcessDetailToolbar = $("#processDetailToolbar").kendoToolBar({
            items: [
                { id: "processDetailAdd", type: "button", spriteCssClass: "fa fa-plus-square", text: "@Resource.Button_AddOperation", overflow: "never", click: processDetailAdd }

            ]
        }).data("kendoToolBar");


        function processDetailAdd() {
            processDetailGrid.addRow();
        }
             processDetailDataSource = new kendo.data.DataSource({

            transport: {
                read: {
                    url: "@Url.Action("ProcessDetailRead", "StandardProcess")",
                    dataType: "json",
                    type: "POST"
                },
                create: {
                    url: "@Url.Action("ProcessDetailCreate", "StandardProcess")",
                    dataType: "json",
                    type: "POST"
                },
                update: {
                    url: "@Url.Action("ProcessDetailUpdate", "StandardProcess")",
                    dataType: "json",
                    type: "POST"
                },
                destroy: {
                    url: "@Url.Action("ProcessDetailDelete", "StandardProcess")",
                    dataType: "json",
                    type: "POST"
                },
                parameterMap: function (options, operation) {
                    if (operation !== "read" && options.models) {
                        return { billId: BillId, details: kendo.stringify(options.models), isUpdate: isUpdate };
                    } else {
                        return {
                            id: BillId
                        };
                    }
                }
            }, schema: {
                model: {
                    id: "Id",
                    fields: {
                        Id: { editable: false, nullable: true },
                        Number: { editable: false, nullable: true },
                        OperationNO: { editable: true },
                        OperationName: { validation: { required: true } },
                        Content: { editable: true },
                        EquipmentName: { editable: true },
                        OperationImag: { editable: true },
                        IsSoftware: { type: "bool", editable: true, defaultValue: "0" },
                       // SoftwareUpLoad: { editable: false },
                        CutterCode: { editable: true },
                        CutterName: { editable: true },
                        measureCode: { editable: true },
                        MeasureName: { editable: true },
                        QuasiTime: { editable: true },
                        TaskTime: { editable: true }
                    }
                }
            }, batch: true
            , requestEnd: function (e) {
                if (e.type !== "read") {
                    //closeCreatePopWindow()

                }
            }
        });
        $("[name=files]").kendoUpload();
        processDetailGrid = $("#processDetailGrid").kendoGrid({
            dataSource: processDetailDataSource,
            height: '98%',
            selectable: "cell",
            resizable: true,
            reorderable: true,
            columnMenu: true,
            editable: false,
            columns: [

                {
                    command: [{
                        name: "deleteItem", text: "<span class=\"k-icon k-delete\"></span>", click: function (e) {
                            if (this.dataSource.total() > 1) {
                                var tr = $(e.target).closest("tr");
                                this.removeRow(tr);
                            } else {
                                showDialog("您不能删除最后一条明细!");
                            }
                            e.preventDefault();
                        }
                    }],
                    sortable: false,
                    title: " ",
                    width: "50px",
                    height: 51,
                    attributes: {
                        "class": "grid-row-operate"
                    },
                    locked: true
                },

                 {
                     field: "OperationNO",
                     title: "@Resource.Field_OperationNO",
                     hidden: false,
                     width: 100
                 }, {
                     field: "OperationName",
                     title: "@Resource.Field_OperationName",

                     width: 200
                 }, {
                     field: "Content",
                     title: "@Resource.Field_Content",

                     width: 200
                 }, {
                     field: "EquipmentName",
                     title: "@Resource.Field_EquipmentName",
                     width: 200
                 }, {
                     field: "OperationImag",
                     title: "@Resource.Field_OperationImag",
                     width: 200
                 }, {
                     field: "IsSoftware",
                     title: "@Resource.Field_IsSoftware",
                     template: "<input name='IsSoftware' class='ob-paid' type='checkbox' data-bind='checked: IsSoftware' #= IsSoftware=='1'? checked='checked' : '' #/>",
                     attributes: {
                         "class": "grid-editable-row",
                         "batch-modify-bind": "ReceivedQuantity",
                         ApplyQuantity: 1
                     },
                     width: 80
                 },
                 {
                     field: "SoftwareUpLoad",
                     title: "@Resource.Field_SoftwareUpLoad",
                     template: "<input type=\'file\' show=\'0\' name=\'files\' id=\'photos\'  />",
                     width: 300
                 },
                 {
                     field: "CutterCode",
                     title: "@Resource.Field_CutterCode",
                     editor: materialCodeAutoComplete,
                     attributes: {
                         "class": "grid-editable-row",
                         MaterialCode: 1
                     },
                     width: 200
                 }, {
                     field: "CutterName",
                     title: "@Resource.Field_CutterName",

                     width: 200
                 }, {
                     field: "measureCode",
                     title: "@Resource.Field_measureCode",

                     width: 200
                 }, {
                     field: "MeasureName",
                     title: "@Resource.Field_measureName",

                     width: 200
                 }, {
                     field: "QuasiTime",
                     title: "@Resource.Field_QuasiTime",
                     editor: quantityNumericTextBox,

                     attributes: {
                         "class": "grid-editable-row",
                         "batch-modify-bind": "ReceivedQuantity",
                         ApplyQuantity: 1
                     },
                     width: 200
                 }, {
                     field: "TaskTime",
                     title: "@Resource.Field_TaskTime",
                     editor: quantityNumericTextBox,

                     attributes: {
                         "class": "grid-editable-row",
                         "batch-modify-bind": "ReceivedQuantity",
                         ApplyQuantity: 1
                     },
                     width: 200
                 }

            ],
            dataBound: function (e) {
                var grid = this;
                var firstItem = this.dataSource.view()[0];

                    this.tbody.find("input[name=files][show=0]").kendoUpload({
                        multiple: false,
                        async: {
                            saveUrl: 'save',
                            removeUrl: "remove",
                            autoUpload: true
                        },
                        validation: {

                            allowedExtensions: [".pdf"]
                        },
                        upload: function (e) {
                            var item = grid.dataItem(this.element.closest("tr"));
                            var id = BillId;
                            this.element.closest(".k-button").addClass("k-state-disabled");
                            this.element.closest(".k-button").find("input[name=files]").attr("show", "1");
                            filescount++;
                            alert(filescount);
                            e.data = { id: id, Operation: item.OperationNO };
                        },
                        remove: function (e) {
                            var item = grid.dataItem(this.element.closest("tr"));
                            var id = BillId;
                            this.element.closest(".k-button").removeClass("k-state-disabled");
                            e.data = { id: id, Operation: item.OperationNO };
                        },
                        success: function (e) {
                            var FileName = e.response.FileName;

                            var item = grid.dataItem(this.element.closest("tr"));
                            item.FileName = FileName;
                            alert(item.FileName);
                            item.dirty = false;
                        }
                    });
            }

        }).data("kendoGrid");
                 });

上传文件之后,点击新增按钮,grid里面上传控件重新加载,使上传的数据清空了
图片说明图片说明

  • 写回答

2条回答

  • louhanbao1 2017-01-11 02:05
    关注

    有没有朋友帮忙解决一下

    评论

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大