Skip to Content
avatar image
Former Member

How to delete row in sap ui5 table???

i am try below code but i getting error

controller.js

Delete:function(oEvent)

{

var tbl=sap.ui.getCore().byId("tableId"); var idx = tbl.getSelectedIndex();

     if (idx !== -1) {

       var m = tbl.getModel();

       var data = m.getData();

       var removed = data.splice(idx, 1);

       m.setData(data);

       alert(JSON.stringify(removed[0]) +  'is removed');

     } else {

       alert('Please select a row');

     } }

del.png (161.1 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    Oct 28, 2015 at 06:10 PM

    or even more generic approach

    var oTable = sap.ui.getCore().byId("tableId");

    var selectedContexts = oTable.getSelectedContexts(true);

    var oModel = oTable.getModel();

    var dataNode = oModel.getData()["DATA_NODE"];

    $.each(selectedContexts.reverse(), function (i, item) {

      var i = parseInt(item.getPath().substr(item.getPath().lastIndexOf("/") + 1));

      dataNode.splice(i, 1);

    });

    oModel.refresh(true);

    DATA_NODE is the name of attribute bound to items of table

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 28, 2015 at 06:06 PM

    so error message tells it all : data is not an array. post your table binding. it must be array with name


    something like data.dataArray or something

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 29, 2015 at 04:44 AM

    Hi Nagaraj,

    try this code

    onDelete: function() {

    if (index !== -1) {

      var m = sap.ui.getCore().byId("tableId").getModel();

      var data = m.getData();

      var removed = data.splice(index, 1);

      m.setData(data);

      m.refresh();

      }

    },

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 20, 2016 at 07:04 PM

    Can I see the this solution? I can't connect that plunk web

    Add comment
    10|10000 characters needed characters exceeded