从表中编辑多行

时间:2014-06-10 09:13:49

标签: odata sapui5

我使用" TwoWay"将ODataModel与表绑定在一起。捆绑。我需要允许用户编辑表格的行,我已经在其中保存了'保存'按钮。目前虽然该表是可编辑的,但我无法编辑表格多行中的条目 请在下面找到我的代码:

var oTable = new sap.ui.table.Table("dprTable",{
        visibleRowCount: 4,
        visible: true,
        navigationMode: sap.ui.table.NavigationMode.Paginator
    });

    var oColumn = new sap.ui.table.Column({
        label: new sap.ui.commons.Label({text: "DBR/DPR"}),
        template: new sap.m.Link({
            "target": "_blank",
            press:[controller.onClickDemoNo,controller]

        }).bindProperty("text","DemoId"),
        width: "auto",
        tooltip: "DBR/DPR"
    });

    oTable.addColumn(oColumn);

    oTable.addColumn(new sap.ui.table.Column({
        label: new sap.ui.commons.Label({text: "Description"}),
        template: new sap.ui.commons.TextView().bindProperty("text", "DemoDesc"),
        width: "auto",
        tooltip: "Description"

    }));

    oTable.addColumn(new sap.ui.table.Column({
        label: new sap.ui.commons.Label({text: "Required Date"}),
        template: new sap.ui.commons.DatePicker("",{
            value:{
                path:"ReqDate",
                type: new sap.ui.model.type.Date({pattern: "dd-MM-yyyy"})
            },
            change: function(){
                console.log('the date is changed and it\'s value is'+value);
            },


        }),
        width: "auto",
        tooltip: "Required Date"
    }));


    oTable.addColumn(new sap.ui.table.Column({
        label: new sap.ui.commons.Label({text: "Requestor"}),
        template: new sap.ui.commons.TextView().bindProperty("text", "RequestorName"),
        width: "auto",
        tooltip: "Requestor"

    }));

    oTable.addColumn(new sap.ui.table.Column({
        label: new sap.ui.commons.Label({text: "Requestor/Project Lead"}),
        template: new sap.ui.commons.TextView().bindProperty("text", "LeadName"),
        width: "auto",
        tooltip: "Requestor/Project Lead"

    }));

    oTable.addColumn(new sap.ui.table.Column({
        label: new sap.ui.commons.Label({text: "Solution"}),
        template: new sap.ui.commons.TextView().bindProperty("text", "SolutionText"),
        width: "auto",
        tooltip: "Solution"

    }));



    oTable.addColumn(new sap.ui.table.Column({
        label: new sap.ui.commons.Label({text: "Start Date"}),
        template: new sap.ui.commons.DatePicker("",{
            value:{
                path:"StartDate",
                type: new sap.ui.model.type.Date({pattern: "dd-MM-yyyy"})
            }
        }),
        width: "auto",
        tooltip: "Start Date"

    }));

    oTable.addColumn(new sap.ui.table.Column({
        label: new sap.ui.commons.Label({text: "End Date"}),
        template: new sap.ui.commons.DatePicker("",{
            value:{
                path:"StartDate",
                type: new sap.ui.model.type.Date({pattern: "dd-MM-yyyy"})
            }
        }),
        width: "auto",
        tooltip: "End Date"

    }));

    oTable.addColumn(new sap.ui.table.Column({
        label: new sap.ui.commons.Label({text: "Estimated Duration"}),
        template: new sap.ui.commons.TextView().bindProperty("text", "EstDuration"),
        width: "auto",
        tooltip: "Estimated Duration"

    }));

    oTable.addColumn(new sap.ui.table.Column({
        label: new sap.ui.commons.Label({text: "Hours"}),
        template: new sap.m.Input("",{}).bindProperty("value", "ActDuration"),
        width: "auto",
        tooltip: "Hours"

    }));

    oTable.addColumn(new sap.ui.table.Column({
        label: new sap.ui.commons.Label({text: "Status"}),
        template: new sap.ui.commons.ComboBox({items: [
            new sap.ui.core.ListItem({text: "New",key:"1"}),
            new sap.ui.core.ListItem({text: "In Process",key:"2"}),
            new sap.ui.core.ListItem({text: "Completed",key:"3"})
        ]}).bindProperty("value","StatusText"),
        width: "auto",
        tooltip: "Status"

    }));

    oTable.setBusyIndicatorDelay(1);
    //oData service call

    var oModel = new sap.ui.model.odata.ODataModel("/sap/opu/odata/sap/ZSECENTRAL_SRV",true);
    oModel.setDefaultBindingMode("TwoWay");
    oModel.attachRequestSent(function (oEvent) {
        console.log('request sent');
         oTable.setBusy(true);
    });
    oModel.attachRequestCompleted(function () {
            console.log('request completed');
            oTable.setBusy(false);

    });
    oModel.attachRequestFailed(function () {
              oTable.setBusy(false);
    });

    oTable.setModel(oModel);
    oTable.bindRows("/DEOPENDBRSet");

设置中是否有待处理的内容?要更新表中的多个记录,我是否必须使用一些批处理操作?任何帮助将不胜感激。

由于

2 个答案:

答案 0 :(得分:1)

对于OData,除非使用批处理,否则一个http请求只能包含一个CRUD操作。因此,对于多个记录更新,建议使用批处理

答案 1 :(得分:0)

我有同样的问题,我仍在寻找解决方案。 您的原始问题将在此处解释:http://scn.sap.com/thread/3372437

我还在搜索的是,如何通过一个模型的多个更改(在不同的对象/实体中)发出“一个”批处理请求?

我希望有类似的东西:     oModel.applyChangesAsBatch();

现有元素的所有更改都使用绑定控件完成。 如果是新创建的实体,当然必须再次调用在模型上创建它。

换句话说:有没有办法使用普通绑定模型并告诉模型将一个请求(可能是批处理)中的所有更改发送到服务器,以便服务器能够存储“全部”或“没有” “?