Let's follow up this discussion at the Neptune Community

(this forum will be kept in read-only mode)

Appending a Form to a Table structure

Hi,


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?


Thanks,

Brandon 


Hi Brandon


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 ?


Regards

Ole Andre   


1 person likes this

Hi Ole-Andre,


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 

  • add the item
  • delete a row as well as 
  • when they press on a row the form is automatically populated with the data from that row that they can then edit.
I'm struggling to get the context of the row itself and not just one field of that row.


Thanks,

Brandon

Hi Brandon,


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

 


You will find Javascript Helpers very useful in NAD.   Whenever you are editing javascript, right click on the screen.


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 !

Kind regards,

Julian

Hi Julian,


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.


I used

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

Hi Julian,


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.



Login or Signup to post a comment