Let's follow up this discussion at the Neptune Community
(this forum will be kept in read-only mode)
I've got a strange situation while using ModelData.Add(oTable, modeloSimpleForm.oData); to append a line structure from a form to a table structure.
The table structure seems to prepopulate itself with the data from the form before the add button action has completed?
So what happens is the form is filled out, the add button is clicked and the first row is added to the table structure. Then when you refill out the form and click add, a new row is added but the data in the first row is changed to the data in the second row effectively giving you two identical rows. This happens when adding a third row except now all three rows are identical?
Is there something I could be missing?
What happens is the inheritance of the binding. So changing the form binded data will then reflect in the previous data. To avoid it we can decouple it from the model like this;
var rowData = JSON.parse(JSON.stringify(modeloSimpleForm.oData)); ModelData.Add(oTable, rowData );
Can you try that first ?
Thanks that worked perfectly!
With the above in mind do you mind also explaining how to apply this to deleting a row from the table?
I'm essentially trying to have the form sitting at the top of the application with the table rows below. You fill out the form and either
to delete a row from your table, you can use ModelData delete. For example:
// on item press of my table -> get Selected Row
// List Get Selected Row var selectedItem = this.getSelectedItem(); var context = selectedItem.getBindingContext(); var werks = context.getProperty('WERKS'); ModelData.Delete(myTable, "WERKS", werks, "EQ");
Also, to get the full row instead of just one field, you can use context.getObject():
// List Get Selected Row var selectedItem = this.getSelectedItem(); var context = selectedItem.getBindingContext(); var row = context.getObject();
Hope you are having some fun with NAD !
Thank you for the help. However, I still can;t get it to identify the current row and delete it using the table or list Delete button function.
var selectedItem = this.getSelectedItem();
var context = selectedItem.getBindingContext();
var row = context.getObject();
but I keep getting the error
Any idea why I might be experiencing this?
Your are welcome, Brandon. No problem, we will make it work. :)
I forgot to mention where I was putting the code I sent you: in the ItemPress of the Table component.
In your code, this.getSelectedItem() is not giving any results.. my question now is: where are you putting your code?
Please send me a couple of screenshots ;)
I've added the code to the "delete" section and tried it in both a list and a table with the same null error.
I've also tried adding the code in the ItemPress section with the same result.