I have a page which contains a table (see example). When the user clicks on a title within the table, a second table is loaded using the Ctools AJAX functions (see example2).
What I am trying to do is work out how I can reload the page programmatically so that both tables are reloaded (e.g. the page should appear as it does in example2).
Is it possible to trigger the Ctools AJAX event which loads the second table using JavaScript/jQuery?
Here is copy of the page callback function
/**
* Loads the view 'namecards_contacts_by_org' using Ctools AJAX
*/
function namecards_contacts_by_org($js = FALSE, $nid) {
$output = '<tr class="namecards-ajax-results-row"><td colspan="2">';
$output .= views_embed_view('namecards_contacts_by_org', 'default', $nid);
$output .= '</td></tr>';
if ($js) {
ctools_include('ajax');
$commands = array();
$commands[] = ctools_ajax_command_remove('tr.namecards-ajax-results-row');
$commands[] = ctools_ajax_command_after('tr.namecards-ajax-link-row-' . $nid, $output);
ctools_ajax_render($commands);
// above command will exit().
}
else {
return $output;
}
}
Comments
Comment #1
begun commentedI just figured it out. Used the jQuery trigger() function. Added the following line to hook_init() function
Comment #2
ayalon commentedUsing the init function to add inline javascript is in my eyes super bad coding style...
Comment #3
begun commentedThanks for your comment. Could you perhaps elaborate on what would be the correct way to do it? I had read somewhere that hook_init() was useful for adding css and javascript to pages. Is the problem with using inline javascript? or the use of hook_init() to insert JavaScript? or both?
I am fairly new to module development and would greatly appreciate any pointers on how to improve my coding technique.
Regards
Comment #4
nymo commentedNot that i think your way is incorrect, maybe this module could prove useful to you: Context Add Assets (http://drupal.org/project/context_addassets).
I imagine you don't that event triggered on every page so it could be better if you encapsulated the javascript code in a file that would only be loaded in a context.
Comment #5
begun commentedThanks for the suggestion. I didn't know about this module; I will certainly check it out. In the end, I made use of a conditional statement within hook_init() to ensure that the script was only loaded on certain pages.
Comment #6
japerryClosing this issue as outdated as Drupal 6 ctools is not supported. If this issue is relevant for Drupal 7, feel free to re-open and mark for Drupal 7 (or 8)