2 louhanbao1 louhanbao1 于 2017.01.10 15:35 提问

kendo ui grid里有一列是上传控件upload,grid增加行addrow,如下图 200C
   <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
louhanbao1   2017.01.11 10:05

有没有朋友帮忙解决一下

zhang020131515
zhang020131515   2017.04.20 18:46

您好,您这个问题怎样解决的

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!