I am trying to manipulate a table to include ‘invisible’ cells to accommodate colspan not being supported by DataTables however I’ve run into a roadblock that I hoped someone might be able to help with…
I have a repeat children expression on the table body which gives the required number of table row elements and have added another repeat children element on the table row tag to produce the required td elements. This all works fine but to get the relevant record to show in the cell I need the $index from both the row and tbody expressions.
If I use a dmx-repeat on the row I can access parent.$index to get the tbody index but, because my case uses the repeat children component
you can’t seem to navigate to the parent.
I have tried parent.$index with no success - can you do this with repeat children?
The difficulty is that I need the repeat to apply to the cell that shows the data and has a colspan value as well as producing the relevant quantity of hidden cells - hence why the repeat children (not repeat) is required.
You can create a variable in the parent repeat, set its value to $index and access its value in the nested one.
The variable value will be available in the current repeat scope only. Example:
As you can see, I’ve worked out that I can put the variable in a hidden row but it doesn’t alter the issue that I can’t access a parent repeat child from within another repeat child. I’m also
You can’t access the values using $parent that’s why you need to use a variable in the main repeat and call its value in the nested repeat to access parent properties.
Have used this setup many times, and it works well.
What looks wrong here is that you have HTML (the variable) between TABLE & TR tags, which is not allowed. Move the variable inside TD tag and see if that works.
Another suggestion: set a KEY on the repeat. Always do that on repeat-children components.
Thanks Siddhant,
Unfortunately, if I move the variable within the TD it is then inside the repeat child that prevents it seeing the parent repeat child.
The table generally works well, it is just because of needing the colspan attribute and DataTables then needing hidden columns to compensate making it more difficult than it should be…
@bpj did you ever figure this out. Same thing appears to be happening to me. Trying to access the $index of the parent loop from a dynamic loop to make the columns. The variable doesn't seem to be getting set and is gone in the Dom.
Would love to see your work around if you have one.