2016-10-11 132 views
1

我想在表sapui5中按行刪除數據,但出現錯誤。我有ID爲「tableKelompokPeserta」的表。從表sapui5獲取value屬性

代碼:

deleteButton2 : function(){ 
     var oTable = this.getView().byId("tableKelompokPeserta"); 

     oTable.attachRowSelectionChange(function(oEvent){ 

      var currentRowContext = oEvent.getParameter("rowContext"); 
      var selData = extModel.getProperty("template", currentRowContext); 
      console.log(selData); 
      sap.m.MessageToast.show(currentRowContext); 
     });   

    }, 

    onInit : function(){ 

     var router = sap.ui.core.UIComponent.getRouterFor(this); 

     var uri = "http://172.16.50.202:8081/id/co/taspen/joinDevelopment/modules/tks_mantab/service.xsjs?cmd=get"; 
     var jsonMod = new sap.ui.model.json.JSONModel(uri,true); 

     var oTable = this.getView().byId("tableKelompokPeserta"); 
     oTable.setModel(jsonMod); 

     var oColumn1 = new sap.ui.table.Column({ 
      label : new sap.ui.commons.Label({ 
       text: "KODE KELOMPOK", 
       textAlign : "Center"}), 
      template : new sap.ui.commons.TextField().bindProperty("value", "KODE_KELOMPOK"), 
      sortProperty : "KODE_KELOMPOK", 
      filterProperty : "KODE_KELOMPOK" 
     }); 

     var oColumn2 = new sap.ui.table.Column({ 
      label : new sap.ui.commons.Label({ 
       text: "NAMA", 
       textAlign : "Center"}), 
      template : new sap.ui.commons.TextField().bindProperty("value", "NAMA"), 
      sortProperty : "NAMA", 
      filterProperty : "NAMA" 
     }); 

     var oColumn3 = new sap.ui.table.Column({ 
      label : new sap.ui.commons.Label({ 
       text: "MINIMAL USIA MASUK", 
       textAlign : "Center"}), 
      template : new sap.ui.commons.TextField().bindProperty("value", "MINIMAL_USIA_MASUK"),  
      sortProperty : "MINIMAL_USIA_MASUK", 
      filterProperty : "MINIMAL_USIA_MASUK" 
     }); 

     var oColumn4 = new sap.ui.table.Column({ 
      label : new sap.ui.commons.Label({ 
       text: "MAKSIMAL USIA MASUK", 
       textAlign : "Center"}), 
      template : new sap.ui.commons.TextField().bindProperty("value", "MAKSIMAL_USIA_MASUK"), 
      sortProperty : "MAKSIMAL_USIA_MASUK", 
      filterProperty : "MAKSIMAL_USIA_MASUK" 
     }); 

     var oColumn5 = new sap.ui.table.Column({ 
      label : new sap.ui.commons.Label({ 
       text: "TERUSAN", 
       textAlign : "Center"}), 
      template : new sap.ui.commons.TextField().bindProperty("value", "TERUSAN"),     
      sortProperty : "TERUSAN", 
      filterProperty : "TERUSAN" 
     }); 

     var oColumn6 = new sap.ui.table.Column({ 
      label : "ACTION", 
      template : new sap.ui.commons.Button({ 
       icon : "sap-icon://edit", 
       tooltip : "{KODE_KELOMPOK}", 
       press : function(){ 
        var id = this.getTooltip(); 
       } 

      }) 
     });   

     oTable.addColumn(oColumn1); 
     oTable.addColumn(oColumn2); 
     oTable.addColumn(oColumn3); 
     oTable.addColumn(oColumn4); 
     oTable.addColumn(oColumn5); 
     oTable.addColumn(oColumn6); 
     oTable.bindRows("/d/results");  

    } 

我有6列,我想獲得 「KODE_KELOMPOK」 欄中選中行(單選只)。我想點擊deletebutton2時,我會得到「KODE_KELOMPOK」(來自oColumn1)。以及如何禁用sapui5中的多行?謝謝。

問候,

鮑比

回答

0

關於第一個問題,在您的deleteButton2事件處理程序,使用oEvent對象來獲取按下刪除按鈕的排:

deleteButton2 : function(oEvent){ 
    var sValue = oEvent.getSource().getParent().getBindingContext().getProperty("KODE_KELOMPOK"); 
} 

sValue將包含所選行的KODE_KELOMPOK模型屬性的值。

對於第二個問題,可以使用List控件的mode屬性設置列表選擇模式。支持的值可以在here找到。 SingleSelectMaster似乎對你有好處。