Skip to Content

best way to check if a row already exists in ui5 before insertion

Hi Guys,

what will be the best way to check if the row is already exists in UI5 table before insetion a new record in ui5 table.

I thought i will check the record which i'm going to insert by doing oModel.Read and if the record exists then give message to user if not insert a new record.

Can you share your views or the methods?

Thanks,
Anurag

Add a comment
10|10000 characters needed characters exceeded

Related questions

3 Answers

  • Best Answer
    Posted on Sep 11, 2017 at 01:29 PM

    Hi Anurag,

    My suggestion is to use model to check the duplicate which is associate with the table.

    We have array.map function in javascript.

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map

    oTableModel = this.getModel("TableModel");
    oTableModel.getProperty("/Items");
    var iIndex = oTableModel.map(function(img) {
    	return img.id;
    }).indexOf(pass_inserted_Id);
    

    It will return true, if that model already contains same id.

    Using this you can avoid duplicated in your table.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 06, 2017 at 07:10 AM

    For the data in a view control ex: table, we can either check for the data through the control id or through the model bound to the control.

    I would suggest, checking with the model data, as based on the entries of the model the rows are created in the control.

    If the model is empty, then there are no rows in the table.

    Regards,

    Sharath

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Sep 07, 2017 at 11:17 AM

    Hello,

    You can check with the key of your entry. If your table is bound to OData model, then you can check if the entry exist with that code :

    var entry = myOdataModel.getProperty("/myService(key1='value1',key2='value2')");

    The entry variable will tell you if there is something or not.

    Regards

    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.