Skip to Content

How to clear table's data in sapui5?

Hello UI5 people,

Please tell me how to clear table's data? When i click on Refresh button i want everything from my table to get removed. Table should become empty i.e should not show any data.

I am using following code to clear textboxe:

sap.ui.getCore().byId('dlrNum-col0-row0').setValue('');

which is working fine, but there will be many rows and columns in the table so there must be a way to clear data in just one go without writing much of code.

Please help,

Thank you,

Regards,

Chetna

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • Best Answer
    Posted on Apr 02, 2015 at 11:03 AM

    var table = this.getView().byId("idTable");

    var oModel1 = new sap.ui.model.json.JSONModel();

    var data =[];

    oModel1.setData(data);

    var aData = oModel1.getProperty("/d/results");

    oModel1.setData({ modelData : aData });

    table.setModel(oModel1, "odata");

    Add a comment
    10|10000 characters needed characters exceeded

    • Hie Robin,

      There is another problem which is bothering me. I have written code inside change event of control so now even when i am navigating to another screen by pressing alt+tab, change event is getting triggered. I dont want this unstability in the application.

      Can you suggest something??

      Regards,

      Chetna

  • Posted on Aug 13, 2015 at 08:56 AM

    One liner:

    sap.ui.getCore().byId('table_id').setModel(new sap.ui.model.json.JSONModel({data: []}));

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 04, 2015 at 09:22 PM

    The following one also works:


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


    if (oTable.isBound("rows")) {

    oTable.unbindRows();

    }

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Apr 02, 2015 at 11:21 AM

    Write this code in your refresh button press. Just destroy the table data and set nodata. Like this below.

    var table = sap.ui.getCore().byId("xxxx");
    table.destroyColumns();
    table.setNoData(new sap.ui.commons.TextView({text: "Sorry, no data available!"}));
    
    

    Regards,

    Mj

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Apr 02, 2015 at 11:55 AM

    sorry for wrong assumption . Did you tried to refresh the table model??

    like this?

    sap.ui.getCore().byId("tableId").getModel().refresh(true);
    
    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.