As title says, I have a URL which I need to call when someone clicks on delete button. I already have a primary key which I need to set and append in delete URL. How'd I do that?

enter image description here


Rows are being generated as:

{% if posts is defined %}
    {% for post in posts %}
        {% set rows = rows|merge([
        {% set index = index+1 %}
    {% endfor %}
{% endif %}

Because the table saves the inputs as JSON they are not individually deleted from the backend.

The way the table works is, when you click a delete button javascript removes those inputs for each cell from the form. When the user saves the form it saves the updated cells as JSON, if there are any.

However if you are saving each row individually then I would listen for the click of the delete button. When clicked, grab your id, then call your plugin action method for delete by using this:

Craft.postActionRequest('pluginname/controller/deleteMethod', {params:value}, function(data){ 
   "do stuff if needed…"; 
| improve this answer | |
  • I did not think of mass removal. Definitely it's doable. But how would I know which fields have actually been removed? Other is, I remove all data first and then update with specified fields. – Volatil3 Oct 27 '15 at 15:37
  • The inputs are saved in an array format, fields[theTable][1][col2]. You are just converting the array into JSON and saving the JSON string to the database. So if a row is absent it doesn't show up in the JSON string. This way you don't have to worry about a specific row being deleted. – aran Oct 27 '15 at 15:46
  • I am actually using PHP's typical POST and reading $_POST variable. My question is, if a row is removed from front, I need to remove that record from backend Db too. How'd I know those deleted rows? – Volatil3 Oct 27 '15 at 15:49
  • As you populate the table you could assign the id via a data attribute. data-row-id="primarykey". Then as you listen for delete button grab that data attribute variable and pass it via the Craft.postActionRequest to your controller. – aran Oct 27 '15 at 15:53
  • >data-row-id="primarykey". I am not finding the way to do it otherwise would have done it earlier :/ – Volatil3 Oct 27 '15 at 16:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.