In Sugar, subpanels of a particular module appear whenever that module has a relationship with another module that is either a one-to-many, or a many-to-many relationship. The relationship determines what subpanels will appear and where. For example, if you have an accounts module with a one-to-many relationship with users, then, when you bring up a detail view of accounts, you will see a user's subpanel with a list view of users. If you have a many-to-many relationship with another module then both modules will have subpanels from the other module.
Subpanels in Sugar come with Top Buttons at the top of the subpanel for the overall subpanel, which are usually a "Create", "Search", and "Select" buttons. Each record in the subpanel may have side buttons to the right for working with that particular record. These buttons usually are "Edit" and "Remove" buttons.
The columns in the subpanel are set up in layouts in Studio at module->subpanel layout, where you can place a particular field you want to see in the subpanel, and determine how much width each column will take up in the layout. Each column will have up and down triangles next to the column name, which if clicked, will sort the records in the subpanel in ascending or descending order depending on which triangle you click.
Out of the box, this is pretty nice functionality from Sugar and most users will be satisfied with the out-of-the-box set up. However, you know, and I know that developers want to tweak, and tweak you can with subpanels. So let's go over how to do some of the tweaks, which are, for the most part, hard to find in the documentation.
Top buttons in a subpanel are found in: "modules/[your module name]/metadata/subpanels/[file name.php]"
This is a core file, so you should make a copy of the file and put it in: "/custom/[your module]/metadata/subpanels/[file name.php]" before doing any editing to be upgrade safe.
To remove a button(s), Open the file you'll find an array called 'top_buttons'. If you want to remove one or more top buttons, just edit them out of the array.
If you want to add a top button, add the button to the array using a preconfigured Sugar widget class.
Sugar provides Preconfigured SugarWidget buttons for developers. They are located at: "include/generic/SugarWidgets/"
Pick a button that is entitled "SugarWidgetSubPanelTop......php" with a Top in the file name. This is the name to refer to as the 'widget_class' in the subpanel array.
Setting the Initial Sort Order
The above file also controls the initial sort order for the records listed in the subpanel. In the top array place the following lines:
'sort_order' => 'asc', or 'sort_order' => 'desc',
'sort_by' => 'id',
These two fields should be placed in the top array and not in a specific field array. 'Sort_order' determines which direction the records will be sorted and 'sort_by' is the database column namel of the field you want to sort by.
Setting Sort Order by Column
If you want to remove the sorting of certain columns in the subpanel, in other words, remove the little up and down triangles for a particular file, since it doesn't make sense to sort by that column, use the same file as above.
Each field in the file appears in the "list_fields" array. These are the fields you set up in Studio for the columns in the subpanel. If you don't want to mess with Studio graphic interface, you can just come here and set up the fields and column widths quickly.
In the array for each field in your subpanel, you can configure which column(s) is sortable or not. By default, all columns are sortable. If you want to not have the user sort by one, or more, of the columns, put this field in the array: 'sortable' => false. That's all there is to it.
Individual Record Side Buttons
Finally, we come to the side buttons for each record. They are located at the bottom of the same file we were using for individual sort order:
"custom/modules/[your module name]/metadata/subpanels"
At the bottom of the "list_fields" array you'll find the buttons for the side buttons.
Remove Side Button(s)
Just comment out the button in the array and that will remove the button.
Add a side button to the record.
Go back to "include/generic/SugarWidgets" and Sugar has provided side widgets for you. Add another button array in the "list_fields" array and put in the name of one of the subpanel widget buttons, be careful that you don't use a "Top" button widget.
Remove links from SubPanel records
Most records in a subpanel have a link that if clicked on take you to the detail view of that record. This is done in this same file "custom/modules/[your module name]/metadata/subpanels."
Remove the link. The links for the field if its a record name show up like this:
'widget_class' => 'SubPanelDetailViewLink', if you comment this widget_class out of the array, the link will disappear.
Add a link. If a field doesn't have a link and you want to add one, just drop 'widget_class' => 'SubPanelDetailViewLink', in the array for that field.
The last thing you have to do if you make any edits is to do a admin->repair->Quick Repair and Rebuild
One last note, if you're not seeing the results your expecting, that's because Sugar caches everything, as well as, your browser caches. The chances are that even after a rebuild, you'll not see the results of your edits, which is very frustrating. Try deleting the Sugar cache, and your browser history, or use a different browser.
Well, that's all folks, I wanted to keep this short and sweet.