Using sort links on columns of custom subpanel not working

I made 2 custom subpanels under Accounts which shows Account AND the Account’s Opportunities’ ACTIVITIES and HISTORY.

In custom/Extension/modules/Accounts/Ext/Layoutdefs/FILENAME.php is a definition for each ‘all_activity’ and ‘all_history’
These each use a collection_list just like Accounts/metadata/subpaneldefs.php except using a function for ‘get_subpanel_data’
These functions each use a query to get its respective list.
All of this works…
clicking any sort at the top of a column retrieves a different data set. It seems that notes and calls return no records, but email remains. I realize each module works a bit differently but this… I have not yet figured out. If anyone has insight, let me know. thanks

Perhaps I went about this the wrong way? The functionality I need:
In Account detail view, in the Activity subpanel and the History subpanel, to see a list for not only the focus Account but also for all Opportunities under that account.
I thought it would be easiest/best to make new subpanels which query the combined lists… but this leads to the sorting problem mentioned above. Another option would be to add a field in in each table involved (Tasks, Calls, Emails, Notes, etc) to hold the owning Opportunity related Account ID . I haven’t tried this but I’m guessing it could work, but duplicating data (storing the account id instead of using a join query) seems unnecessary and would make extra work trying to move the Opportunity to another Account. Since most modules offer explicit ownership by a Contact as well as an Account-OR-Opportunity it seems difficult to include both Account and Opportunity activity records.
Any other ideas out there?

Hmmm, no ideas out there huh? Well, I’m trying to dig into the ‘SubPanelViewer’ action… clearly, somewhere the data is being requeried… arrrrgggg!!!

YES! Figured it out.
In my custom sql I included a WHERE:
WHERE calls.deleted!= ‘1’ AND ( (calls.parent_type=‘Opportunities’ AND = ‘".$accountId."’ ) OR (calls.parent_type=‘Accounts’ AND calls.parent_id=’".$accountId."’) )

the accountid variable came from:
$args = func_get_args();
$accountId = $args[0][‘account_id’];

… which apparently isn’t being sent to this function when called. So I included an if statement:
if($accountId==’’) $accountId=$_GET[‘record’];

and voila! If anyone has a similar need and wants more detail, let me know