Forums

How to get Table row key

Elita- 29 Dec, 2024

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:

  1. set the Table name with Wizard Settings>Name - submissions_list
  2. add the table column > Data path rowKey
  3. add the Output > Data path rowKey; HTML - PHP code with tags.
  4. change $this->get('submissions_list.key') to WHAT? $row["key"] is not working. $row.key is not working either. 
Max_admin 30 Dec, 2024
Answer

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

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Elita- 30 Dec, 2024

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

Elita- 30 Dec, 2024

In addition, CF6 had the Select gcb[] option. I cannot see it in CF8. Do you plan to implement that?

Elita- 31 Dec, 2024

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.

Max_admin 31 Dec, 2024

I just did it here the way I explained to you:

before the table:

and inside the counter column:

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Elita- 31 Dec, 2024

khm... Thank you for the tip - however, I get different numbers and each time i refresh the window it gets higher :D 

Max_admin 31 Dec, 2024

are you sure you have defined the variable to 0 before the table ?

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Elita- 31 Dec, 2024

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

Max_admin 01 Jan, 2025

do you have the rowkey variable defined anywhere else ? there must be some conflict because it worked fine here

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Elita- 01 Jan, 2025

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.

Max_admin 01 Jan, 2025

the variable is defined and set to 0 on the same page which you refresh ?

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Max_admin 03 Jan, 2025

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 ?

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Elita- 03 Jan, 2025
1 Likes

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

Max_admin 04 Jan, 2025

great, glad you have it working now!

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
You need to login to be able to post a reply.