Friday, 16 November 2018

SAPUI5 TABLE SELECT ROW AND DELETE AND SHOWING ALART HI

VIEW.JS
sap.ui.jsview("ex.ex", {


getControllerName : function() {
return "ex.ex";
},


createContent : function(oController) {
var data = [
    {lastName: "Dente", Name: "Al"},
    {lastName: "Friese", Name: "Andy"},
    {lastName: "Mann", Name: "Anita"}
  ];
var oModel = new sap.ui.model.json.JSONModel();
  oModel.setData(data);
var oTable = new sap.ui.table.Table("mytable",{
//id:"mytable",
visibleRowCount: 3,
    width : "85%"
});
 
  oTable.addColumn(new sap.ui.table.Column({
    label: new sap.ui.commons.Label({text: "lastName"}),
    template: new sap.ui.commons.TextView({text:"{lastName}"})
  }));
  oTable.addColumn(new sap.ui.table.Column({
    label: new sap.ui.commons.Label({text: "Name"}),
    template: new sap.ui.commons.TextView({text:"{Name}"})
  }));
  oTable.setModel(oModel);
  oTable.bindRows("/");
var btn =new sap.m.Button({
        text:"delete row",
        press:oController.sample
           

        });
       
       
       
  return new sap.m.Page({
title: "Title",
content: [
oTable,btn
]
});
}


});
controller.JS
sap.ui.controller("ex.ex", {


/* onInit: function() {
viewEx=this;
},*/


// onBeforeRendering: function() {
//
// },


// onAfterRendering: function() {
//
// },


// onExit: function() {
//
// }

sample:function(){
var oTable = sap.ui.getCore().byId("mytable");
var id = oTable.getSelectedIndex();
        if (id !== -1) {
          var m = oTable.getModel();
          var data = m.getData();
          var removed = data.splice(id, 1);
          m.setData(data)
          sap.m.MessageToast.show(JSON.stringify(removed[0]) +  'is removed');
        } else {
          sap.m.MessageToast.show('Please select a row');
        }
alert("hi");
}

});
INDEX.HTML
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv='Content-Type' content='text/html;charset=UTF-8'/>

<script src="resources/sap-ui-core.js"
id="sap-ui-bootstrap"
data-sap-ui-libs="sap.m,sap.ui.table,sap.ui.commons"
data-sap-ui-theme="sap_bluecrystal">
</script>
<!-- only load the mobile lib "sap.m" and the "sap_bluecrystal" theme -->

<script>
//var viewEx;
sap.ui.localResources("ex");
var app = new sap.m.App({initialPage:"idex1"});
var page = sap.ui.view({id:"idex1", viewName:"ex.ex", type:sap.ui.core.mvc.ViewType.JS});
app.addPage(page);
app.placeAt("content");
</script>

</head>
<body class="sapUiBody" role="application">
<div id="content"></div>
</body>

</html>
OUTPUT

No comments:

Post a Comment

test ganaral binding(testing )

  /home/user/projects/project1/webapp/model/record.json: {     "text" : "outer text" ,     "myrecorsd" : [    ...