cancel
Showing results for 
Search instead for 
Did you mean: 

TABLE EDIT/UPDATE VALUES

Former Member
0 Kudos

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.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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);

Former Member
0 Kudos

Hello Zühnja,

Thank you for your solution yes it works for me !

Regards,

Ogulcan G.

Answers (1)

Answers (1)

karthikarjun
Active Contributor
0 Kudos

Hi Ogulcan,

Will this help?

JS Bin - Collaborative JavaScript Debugging

Go to First name or lastname line item ---> edit/update is working good

Thanks,

KA

Former Member
0 Kudos

Hi Karthik,

Thanks for your reply, but I need a button which is name Edit. And when I press it selectedRow values should come to textfields and when I edit the value, table should change with edited data.

I can't use editable right now

Thanks,

Ogulcan G.