Migxdb Conditionally editable rows?

I’ve used Migxdb to set up a grid TV to edit linked entries from a custom table inside my resources. It works great and was so quick to set up :smiley:

I have an unusual need however: some of the rows in the custom table come from an external data source and are updated automatically. They need to display in the migxdb grid but not be editable. Other rows have been added by MODX users and need to be editable.

My custom table has an is_editable column, but I haven’t been able to find a way to lock grid rows based on the value of this column. Is there a way to do this?

Maybe instead of the normal “update” context menu, you could create a custom context menu that only shows the update-window if the row is editable.

Or you could create a custom update processor, that doesn’t save the changes, if the row isn’t editable.

I like the idea of a custom context menu! Any pointers for how to tie that into MIGX?

There is an example for a custom context menu in this Youtube video (around minute 8:40)

For the code, maybe use the original “update” code:

Then add some code to only conditionally call this.loadWin() by checking the value in the selected record (this.menu.record).

1 Like

It’s probably better to only add the context menu item, if the row is marked as editable, by checking the column value before the handler gets executed.

Code like this may work:

<?php
$gridcontextmenus['myupdate']['code']="
    if (n.is_editable == 1) {
        m.push({
            text: 'My Custom Edit',
            handler: 'this.myupdate'
        });
    }
";

$gridcontextmenus['myupdate']['handler'] = 'this.myupdate';

$gridfunctions['this.myupdate'] = "
    myupdate: function(btn,e) {
        this.loadWin(btn,e,'u');
    }
";