Quantcast
Channel: SCN: Message List - SAP Fiori
Viewing all articles
Browse latest Browse all 2526

Re: Adding Blank rows to the table in add new row button

$
0
0

Please refer below example code.it should be useful. refer this JS Bin - Collaborative JavaScript Debugging

and Add Row in a SAPUI5 Table using xmlModel | SCN


  1. <!DOCTYPE HTML>   
  2. <html>   
  3. <head>   
  4. <title>Add Rows in Table without Data </title>   
  5.     <meta http-equiv="X-UA-Compatible" content="IE=edge">   
  6.     <meta http-equiv='Content-Type' content='text/html;charset=UTF-8' />   
  7.     <script src="https://sapui5.hana.ondemand.com/resources/sap-ui-core.js" id="sap-ui-bootstrap" data-sap-ui-libs="sap.ui.commons,sap.ui.table" data-sap-ui-theme="sap_bluecrystal">   
  8.     </script>   
  9.     <!-- add sap.ui.table,sap.ui.ux3 and/or other libraries to 'data-sap-ui-libs'if required -->   
  10.     <script>   
  11.          
  12.             // Model Data (local)   
  13.             var aData = [{ID: "1", lname: "Vijay",   fname: "Kalluri"}, 
  14.                          {ID: "2", lname: "Shyamu", fname: "K"}];   
  15.             // Define a table     
  16.            var oTable = new sap.ui.table.Table({   
  17.                   title: "Line Items",   
  18.                   visibleRowCount: 7,   
  19.                 firstVisibleRow: 3,   
  20.                selectionMode: sap.ui.table.SelectionMode.Single,   
  21.                toolbar: new sap.ui.commons.Toolbar({items: [    
  22.                             new sap.ui.commons.Button({   
  23.                                 text: "Addnew",    
  24.                                 style: sap.ui.commons.ButtonStyle.Accept,   
  25.                                 press: function() {  
  26.                                 var modelData = oModel.getData(); 
  27.                                 var rowCount   = modelData.modelData.length;   
  28.                                 rowCount = rowCount + 1
  29.                                  aData.push({ID: rowCount, lname: " "}); // Push data to Model 
  30.                                    oModel.setData({modelData: aData}); // Set Model 
  31.                                 }})   
  32.                                 ]}),   
  33.                            });   
  34.            oTable.addColumn(new sap.ui.table.Column({   
  35.                label: new sap.ui.commons.Label({   
  36.                    text: "ID"   
  37.                }),   
  38.                template: new sap.ui.commons.TextField({   
  39.                    value: '{ID}',   
  40.                  
  41.                }),   
  42.                sortProperty: "ID",   
  43.                filterProperty: "ID",   
  44.                width: "125px"   
  45.            }));    
  46.            oTable.addColumn(new sap.ui.table.Column({   
  47.                label: new sap.ui.commons.Label({   
  48.                    text: "Last Name"   
  49.                }),   
  50.                template: new sap.ui.commons.TextField({   
  51.                    value: '{lname}',   
  52.                    
  53.                }),   
  54.                sortProperty: "lname",   
  55.                filterProperty: "lname",   
  56.                width: "125px"   
  57.            }));   
  58.            oTable.addColumn(new sap.ui.table.Column({   
  59.                label: new sap.ui.commons.Label({   
  60.                    text: "First Name"   
  61.                }),   
  62.                template: new sap.ui.commons.TextField({   
  63.                    value: '{fname}',   
  64.                   
  65.                }),   
  66.                sortProperty: "fname",   
  67.                filterProperty: "fname",   
  68.                width: "125px"   
  69.            }));   
  70.             //Create a model and bind the table rows to this model   
  71.             var oModel = new sap.ui.model.json.JSONModel(); // created a JSON model         
  72.             oModel.setData({ // Set the data to the model using the JSON object defined already   
  73.                 modelData: aData   
  74.             });   
  75.             oTable.setModel(oModel);   
  76.             oTable.bindRows("/modelData"); // binding all the rows into the model   
  77.                      
  78.             //Place the Table on the UI   
  79.             oTable.placeAt("MemTable");   
  80.            
  81.     </script>   
  82. </head>   
  83. <body class="sapUiBody">   
  84.     <div id="MemTable"></div>   
  85. </body>   
  86. </html>


Kindly let me know if you need any more information


Viewing all articles
Browse latest Browse all 2526

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>