Hi, I need your help in figuring out how to get thable rowkey on CF8.
I need this to create a simple code thet would echo a row number for my table.In CF6 the code was :
$rowKey = $this->get('submissions_list.key');
$rowKey = $rowKey + 1; // row number starts from 1, not by default 0
echo $rowKey;
To replicate this on CF8, If I understand correctly, I should do the following:
- set the Table name with Wizard Settings>Name - submissions_list
- add the table column > Data path rowKey
- add the Output > Data path rowKey; HTML - PHP code with tags.
- change $this->get('submissions_list.key') to WHAT? $row["key"] is not working. $row.key is not working either.
Hi Elita
there is no key variable in the table loop, you need to define your own key before the table then use it inside the table using:
$this->set("key", 0);
then you get this table as $rowKey and do the increment like how you do it now
Another way is to modify the SQL for the Read Data and include a row count field, I know this can be done but I do not have an example, and you will need to write the full SQL query in this case
Sorry, Max, I didn't quite catch the idea. 🙁I can set the number, but it's the same for all the rows. Should I create a loop inside the row? That doesn't seem to make sense.How can I print out the data structure or layout of the table so I can see how the table and its rows are constructed?
Elita
In addition, CF6 had the Select gcb[] option. I cannot see it in CF8. Do you plan to implement that?
Max, it seems that the elements are not iterating correctly inside the table. I attempted to create a checkbox for selection manually. However, when I placed the checkbox inside the table rows, all the checkboxes ended up being the same.
In every row, I get the same checkbox with name="checkbox_9"
:
<td class="nui collapsing breakwords">
<div class="field holder">
<div class="nui checkbox">
<input name="checkbox_9" value="1" title="" type="checkbox" class="hidden">
<label tabindex="0">Check this 9</label>
<input name="checkbox_9" value="" type="hidden">
</div>
</div>
</td>
Whereas in CCv6, the value
attribute would iterate through the row sequence, such as:
value="1"
value="2"
value="3"
This issue suggests that the iteration logic for dynamically generating unique checkboxes per row isn’t functioning as expected.and this migt be the same problem with $rowKey.
I just did it here the way I explained to you:
before the table:
and inside the counter column:
khm... Thank you for the tip - however, I get different numbers and each time i refresh the window it gets higher :D
are you sure you have defined the variable to 0 before the table ?
jupp. positive. I wanted to reset it with PHP, but that is not working?
// Reset rowkey to 0 at the beginning of the process $this->set("rowkey", 0);
// Increment rowkey during iteration or processing $this->set("rowkey", $this->get("rowkey") + 1);
do you have the rowkey variable defined anywhere else ? there must be some conflict because it worked fine here
Max, I defined another variable named tablecounter
. It behaves the same way — every time I refresh the window, it keeps incrementing the count. This happens both on the frontend and backend.
the variable is defined and set to 0 on the same page which you refresh ?
Hi Elita
I have applied a fix to the Variables action here earlier and that may affect the result, please try to set the variable using a PHP action:
$this->set("counter", 0);
does that change the result you have ?
Thanx, MAx, this is working:
First PHP (Before the Table):
$this->set("counter", 0);
Second PHP (Inside the Table Row Column)
$this->set("counter",$this->get("counter")+1);
Or the breakdown with variables -
$counter = $this->get("counter"); // Get the current counter value
$counteradd = $counter + 1; // Increment the counter by 1
$this->set("counter", $counteradd); // Store the updated counter value
return $counteradd; // Return the incremented counter
great, glad you have it working now!