Deleting Selected Rows from a Repeat Table

Hi All,

Need your help in deleting selected rows from a repeat table. I have included checkbox and its value when checked is stored in an array. The checkbox values are the IDs of the rows to be deleted.

I am unable to remove the IDs from the array if the checkbox is again deselected after initial selection.

<input class="form-check-input mt-1 ms-0 me-4" type="checkbox" id="upd_delJournal" name="delJournalID" dmx-on:checked="arr1.addUniq(upd_eJournalDetID.value)" dmx-on:unchecked="arr1.removeAt($index)">

I suppose you want to delete multiple records based on the checkbox cjecked/unchecked...
If I'm correct then you should work like Teodor suggested here:

Inside your formRepeat you will include a hidden input of the Journal_id and the select checkbox input. BOTH OF THEM WITH dynamic ids (dmx-bind:id).

Then on Del Journal click, in your serverconnect_form, you add a repeat based on your page's formrepeat and check if checkbox (upd_delJournal.value==1) then delete the current record.

**Just for safety, instead of deleting the record, add a setValue with the current journal_id and output it.
So when you run ir in your browser, on "Del Journal" click you will be abvle to see if the correct ids are outputed. Then you will be safe to replace the setValue with the final DB Delete procedure.

If something is not clear for you please ask

Hey @famousmag I am unable to understand how to implement the solution you proposed.
If possible, can you kindly explain it with few steps.

Your table body will be a formRepeat (like your previous topic)

in the form repeat you have the columns you need

The last column willinclude the hidden joural_id and the checkbox input

You can do this with a form repeat like @famousmag says or you can send the values (1,2) and then on the server connect use a repeat with split (with comma ,) then you use the repeat id to delete the record

PS: Remember to do some backup specially working with deleting records

@famousmag I am sorry for bothering you again, however, i am confused about creating the server connect.
The table is already a part of form repeat & i have an existing server connect to update the main & sub table.
In this scenario, i am unable to understand how to create a server connect which will get the check box values for deleting the rows.

hey buddy, don't worry! :slightly_smiling_face:

I have understood that by clicking the Del Juarnals button, you want ALL the Journals with the checkboc checked to be deleted...
IS THIS WHAT YOU WANT TO DO?
If yes, then have you implement this Teodor's solution from your previous topic?

If you have, then on your serveraction, by assigning the page and the form (that includes the formrepeat) if you click the import from form button, an array will be automatically created in your input $_POST containg the 2 variables , jurnal_id and checkbox_selected

Then add a repeat step based on the $_POST formrepeat and in there check if the checkbox_selected .value==1 then delete the record

  • As I told you, Instead of deleting the record, add a setValue isDeleted = juarnal_id and check the output.
    This way when you run the page and click the Del Juarnals button, you will get on your dev network tab the ids of the Journals to be deleted...
    When you are sure that it is working fine, replace the setValue with the DB delete step

If you don't understand, please share your table code se we can take a look and adjust it accordingly

Hey, Thank You very much @famousmag for the solution & appreciate your patience in answering very silly queries.

Hey @franse thanks for providing your approach too.

Every time i ask issues here, i get to learn something new from your expertise.

Thanks once again!!

2 Likes

I suppose you got it working!

Make sure of everything works as it should and then add the DB delete step... :wink:

1 Like