2014-06-10 21 views
0

我已經使用「雙向」綁定將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"); 

有什麼在設置未決?爲了更新表格中的多個記錄,我必須使用一些批處理操作嗎?任何幫助,將不勝感激。

由於

回答

1

對於OData的,一個HTTP請求可以只包含一個CRUD操作,除非使用批處理。因此,對於多個記錄更新,建議使用批次

+0

感謝瑪雅,說的對。我現在不使用「雙向」綁定。而不是我寫的更改事件處理程序的表格上的所有列的火我正在添加一個批處理操作,並點擊另一個「保存」按鈕,我已經在屏幕上,我提交批處理。 – Supereme

0

我有同樣的問題,我仍然在尋找解決方案。 你原來的問題將在這裏解釋:http://scn.sap.com/thread/3372437

我還在尋找的是,我怎麼能激發一個模型的多個變化(在不同的對象/實體)「一個」批量請求?

我期待的是這樣的: oModel.applyChangesAsBatch();

現有元素的所有更改都通過綁定控件完成。 如果是新創建的實體,當然必須有另一個調用來先在模型上創建它。

換句話說:有沒有辦法對模型使用普通綁定,並告訴模型將一個請求(可能是批處理)中的所有更改發送到服務器,以便服務器能夠存儲「全部」或「沒有」?