Bulk “Delete selected” in my MIGX DB grid doesn’t do anything when you pick multiple rows and click “Delete selected.”
Step to reproduce
Create a custom CMP using MIGX DB (per this tutorial).
in the config make:
“contextmenus”:“remove”,
“actionbuttons”:“bulk”,
“columnbuttons”:“remove”,
In the CMP grid, check multiple rows.
Click Bulk Actions > Delete selected.
Observed behavior
The Delete selected menu item appears but clicking it has no effect.
Rows remain unchanged in the database.
Per-row Remove still works (deletes a single row).
I even tried added the appropriate handlers manually via “extrahandlers”:“this.remove||this.removeSelected||this.deleteSelected||this.delete” but to no avail…
Expected behavior
After selecting multiple rows and clicking Delete selected, the selected db records should be deleted or removed.
Environment
MODX 3.1.2 + MIGX 2.1.0.
Apache
PHP version: 8.3.22
Server version: 10.6.21-MariaDB-cll-lve - MariaDB Server
When running “Bulk Actions” → “Delete Selected”, the code sets the column deleted to true (and also updates the columns deletedon and deletedby). This is very different from the “remove” command in the context-menu, that actually removes the row from the database.
It’s analogous to resources in the MODX manager, where “Delete” only sets the deleted flag and you have to go to the trash-bin manager to remove a resource completely.
Yes, without at least a column named deleted, this functionality won’t work with your custom class.
It’s probably possible to create a custom actionbutton with a custom processor for that.
I created another video about MIGX Customization some time ago. It does explain the general concept of customization in MIGX, but not this exact use case.
I manually aded a deleted field to my custom DB table
Then added this field to the XML schema via the MIGX Package Manager: <field key="deleted" dbtype="tinyint" precision="1" phptype="integer" default="0" />
Saved the schema and ran “parse Schema”.
After that, I had to manually verify all generated model files in core/components/my_custom_package included the new deleted field. Some updated automatically… others didn’t (unsure why).
I added deleted as a column in my CMP grid to confirm it was being set.
Included these handlers in the migx config "extrahandlers":"this.emptyTrash||this.remove||this.update||this.toggleDeleted||this.deleteSelected||this.deleteObject",
Now when i click Bulk Actions > Deleted Selected the deleted column updates to 1 as expected.
Last, I added the emptyTrash action button, and now when emptyTrash is clicked all of the items set to deleted: 1 permanently get permanently removed.
Hope that is helpful to anyone else trying to figure it out!
This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.