Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

TABLE EDIT/UPDATE VALUES

Hello expert,

I have a table which have values from my local. I can add values and delete values also but I want to do edit/update of selected value. I can get the values to my Dialog's Inputs but when I press the button the values are adding like new value to my table (like my add function)

When I select a row I want to edit this. I saw some CRUD examples but I dont need these operations from SAP. I just want to see my local values and edit them.

If you have any example or suggestion, pls send me I really need this for my project.


Edit: "JS Bin - Collaborative JavaScript Debugging" this example is so close to my view. I just need Edit function.

Thanks,

Ogulcan G.

Tags:
Former Member
Former Member replied

Hey Ogulcan

First change your selection mode of your table to Single, like this:

selectionMode : sap.ui.table.SelectionMode.Single,

Then it is clearer that a row can be selected

Then add a function to be called when one selects a row and add it to the rowSelect event in your table, for example

rowSelect:function(event){selectRow()}

Row select should go ahead and add the info in the table to the edit boxes. Maybe add an hidden or uneditable edit box for the id. Just say if you are not sure how to do that. You will need the id of the row that was selected to edit or remove that row from the dataset. So either store it in a field or check if you can find the id with the table's available functions.

Then when add or delete is pressed search for the id you stored in the dataset to determine what the index is , if "2" is the selected id, do this:

var elementPos = mdData.Employees.map(function(x) {return x.id; }).indexOf("2");

This returns the index.

To delete you can do this:

mdData.Employees.splice(elementPos,elementPos + 1);

To edit you can do this:

mdData.Employees[elementPos] = {firstName:"Tian", lastName:"saran",age:"25",address:"Salem", id: "1"};

orĀ  to just edit firstname for example:

mdData.Employees[elementPos].firstName = "Somon"

oModel.setData(mdData);

0 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question