Collections

Editable Drop-Down Select Field in the Grid View

gourmet fare

Editable Grid View

I want to have a field in the Collections child grid view to be able to change the item's "createdby" value. This recipe is the result of a Slack conversation.

sottwell asked...

How to have a custom field in the Collections children grid? Specifically, I want to be able to change the createdby. I can get the createdby user ID in the grid, now I need to show his full name and be able to change it. I would presume a drop-down with users to select from, users probably filtered by group. Is this even possible?

The Solution:

John says...

If you need a dropdown you can use this as an editor:

    {"xtype":"modx-combo-user","renderer":true,"fields": ["fullname","username","id"],"displayField": "fullname","baseParams": {"action": "security/user/getlist","usergroup":2}}
  

and you don’t need any renderer.

What's the Story?

The Collections CMP (Extras -> Collections views) makes it really easy to modify how a Collection's children are displayed in the Children grid. The Collections documentation describes how to add a column, and other features of the Collections views.

The specific goodie here is how to display the 'createdby' user's full name, and how to make this field editable using a select drop-down. Specifically, we want this drop-down to list only users with a specified group assignment. By default, it would display all users, 20 at a time. And, like all modx-combo elements, you can start typing in a user's name to filter the list. But limiting the list to our desired group in the first place is a nice touch.

This is done by specifying an Editor for the field, loading a custom MODX 'modx-combo-user' xtype in the ExtJS used for creating the grid.

Editable createdby field

This element specifies that its "action" is the object found in the /core/model/modx/processors/security/user/getlist.php file, and feeds that object the "usergroup" property. The getlist.php file will filter the list of users so that only users assigned to the specified group are returned for the list. And to make it even more convenient for us, the element specifies that the field that is to be displayed in the grid is the "fullname" value.

Createdby dropdown