Manage sets of 'Player' (custom table) items

The management overview for items in a custom table needs either a purpose-built snippet to extract the relevant fields from the database, or the use of LoopDbChunk (no longer findable in MODX Extras) or similar utility. In this example, the custom ListSections snippet is used. It looks after both display and management, and shows the players in an orchestra in sets under their section.

The Manage Players page has Add and Move buttons at the top, calling on the ItemDropList snippet to generate selection lists linking each item's rank with its ID. So you can preset a new item's position in the list, or change the position of items within the management page.

<form method="post" action="pkdemo-player-edit" id="addItem">
<b>Add item</b> as [!ItemDropList?action=`add` &table=`orchestra` &name=`rank` &extra=`1`!]
&nbsp;&nbsp;<input type="submit" value="Add item" />
</form>

<form method="post" action="pkdemo-player-edit" id="moveItem">
<input type="hidden" name="command" value="move">
<input type="hidden" name="orderBy" value="section,rank">
<input type="hidden" name="returnId" value="[*id*]">
<b>Move</b> [!ItemDropList?action=`move` &table=`orchestra` &name=`to`!]
<input type="submit" value="Move item" />
</form>

<table>
[!ListSections?table=`orchestra` &sections=`Strings,Woodwind,Brass,Percussion,Other,Non-playing||Non-playing members` &outerTpl=`pk.orch.section.manage.tpl` &innerTpl=`pk.orch.player.manage.tpl` &showUnpublished=`1` !]
</table>
 

The ListSections snippet sets up placeholders to be used in two templates: &outerTpl for section headings, and &innerTpl for entries within each section.

Our example chunk for the management page uses a table to diplay the data. Section headings are created as rows of TH elements using the "outer" template chunk, pk.orch.section.manage.tpl

<tr><th colspan="2">[+section+]</th></tr>
 

The "inner" template chunk, pk.orch.player.manage.tpl, generates table rows with TD cells containing hyperlinks for commands to edit, to publish/unpublish items and to delete them. Here the commands and data are written into a URL query string. You could also use forms with Javascript-generated hyperklinks for the Submit action if preferred.

<tr><td style="text-align:right;">[+rank+]</td>
<td title="[+instrument+]"><a href="pkdemo-player-edit?docId=[+id+]&command=edit&returnId=[*id*]">[+player+]</a></td>
<td><a href="pkdemo-player-edit?docId=[+id+]&command=delete&returnId=[*id*]">Delete</a></td>
<td><a href="pkdemo-player-edit?docId=[+id+]&rank=[+rank+]&command=setField&docField=published&myValue=[+changePub+]&returnId=[*id*]">[+pubCmd+]</a></td>
</tr>