0
votes

I have a Calculated Model which generates records based on a query. When I click the update button I want to pull the Certificate_ID Value in the same row as the Update Button. First thing I have tried to do is return the index of the row using by attaching the following code to the Update Button's on click event. Tried using the below code, but not getting the desired result.

Returns the position of the of the button in the row:

var index = widget.childIndex;

Returns blank on the first button and returns 1 for the second button:

var index = widget.parent.childIndex;

Table in App:

enter image description here

Table with Data:

enter image description here

1
ChildIndex will always return a number and refers to the nth element inside a parent element. So your first attempt probably returns 4 since the button is the 5th element in the table row but since index starts with 0 it is 4. The second attempt returns the index of the row relative to its parent which is a list element. If you want to just return the the Certificate_ID I would suggest using widget.datasource.item.Certificate_ID. That will actuallly point to a value from your data vs just an index of an element. - Markus Malessa
Damn that actually worked. I can get the CertificateID using widget.datasource.item.Certificate_ID. If you post an answer I will mark it as correct. I would still be interested in knowing how to return the index of the row the widget is on though. (While Second attempt seems to be correct, still not sure why first row returns as blank and not 0) - New_2_Code
If you log the childIndex in the console via console.log(widget.parent.childIndex) it will always show up as blank vs 0. I'm not actually sure why that is. If you introduced a label into each row and set its value binding to widget.parent.childIndex then it would correctly show 0 in the first row. So pretty much any other type of code besides console.log() would correctly identify the first row childIndex as 0. - Markus Malessa
Wierd, but cool info. Thanks Markus. - New_2_Code

1 Answers

1
votes

For calculated datasources you are still able to use:

widget.datasource.item.YourField

in a button onClick event to get a value from the button click.