I has needing to pass a variable to the table in order to construct the query. Imagine a scenario where you want to make a website where with just one table definition and menu_callback you can:
q=list/2007 list all the nodes in 2007
q=list/2007/9 list all the nodes in september 2007
q=list/2008 list all the nodes in 2008
...
Or inside a node list all the nodes from the node author, or....
I modified ajaxtable_render(... $options=array()) and then ajaxtable_table_mytable($options) can construct de query according to the parameters in "$options". It took me sometime to figure how to get ajaxtable_refresh() and autosearch work with it; but now it does.
I think it would be a good thing to add to your module permanently, I don't know how to make a patch, but I can send you de code so you can do so. I may help to add the documentation.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | ajaxtable.zip | 91.89 KB | enboig |
| ajaxtable.zip | 11.76 KB | enboig |
Comments
Comment #1
ArvindSingh commentedI'm trying to eval the changes as I'm encountered by a similar requirement. Can you show what changes need to go in the code of the calling screen or menu.
Should setting of table['options'] in the table definition sufficient ?
Comment #2
enboig commentedFirst of all I thought of using $override to pass variables, but I didn't like that, so I ended removing override and passing a $options array with the paramters, the table definition will construct its query depending of the options.
The changes I made to the code are:
* function ajaxtable_render($id,$uid='',$refresh=FALSE,$input_value='',$options=NULL) {
I needed some way of passing the variables to the table; I had to change some other lines of the module so the table definition is called with the $options, and the ajax uses it when request for a refresh.
*Menu system:
<? $items[] = array('path' => 'comptacau/proveidors/despeses',
'title' => t('Page title'),
'callback' => 'ajaxtable_render',
'callback arguments' => array(
"id" => "comptacau_taula_despeses",
"uid" => $user->uid,
"refresh" => false,
"input_value" => '',
"options" => array("supplier_nid" => arg(3)),
),
'access' => true,
'type' => MENU_CALLBACK);
?>
Here it receive a nid and passes it to the table, it will construct the query according to the nid. I didn't change the parameters order so it is full compatible with previous version.
If calling it inside a page it must be called with ajaxtable_render('my_table', $user->uid,FALSE, '', array('assentament_nid'=>$node->nid)
With my code you can list all nodes published by a used; all the nodes from a month, etc...
An example of a table definition is pasted below; I commented some lines of the provided examples, and I use SESSION variables also.
I am still working in this table, but it works right now.
Comment #3
ashokkumarc commentedThis is Ashok ,
i am tested the following file
ajaxtable.zip 11.76 KB
when i am used this default document table given in render(ajaxtable_example1....example7) are works fine , but
searching and sorting works fine , but if ia have copied it and add this in body tag and called it in render doesnt works ,
that means sorting , searching returns empty.
In body
print ajaxtable_render("ajaxtable_example2");
works fine
but following not works
function ajaxtable_table_ajaxtable_ex2($override='') {
$search_inputs = array(
array(
'type' => 'text',
'id' => 'is_like_title',
'operator' => 'like',
'help_title' => 'Like',
'help' => 'Search the node titles matching this phrase',
'col' => 'title',
'attributes' => array(
'size' => '5',
),
),
array(
'type' => 'text',
'id' => 'is_not_like_title',
'operator' => 'not like',
'help_title' => 'Not like',
'help' => 'Search the node titles that do not match this phrase',
'col' => 'title',
'attributes' => array(
'size' => '5',
),
),
);
// Get the inputs so they can be added to search
$inputs = ajaxtable_search_inputs($search_inputs);
// Alter the theme's search bar template to include the
// additional search inputs.
$theme['search'] = '
';
// Change the text of the buttons
$theme['button_text'] = array(
'search' => 'Search',
'jump' => 'Jump to page',
'next' => '>>',
'prev' => '<<',
);
$table = array(
'theme_override' => $theme,
'rows' => 10,
'theme_module' => 'ajaxtable',
'pages' => 15,
'theme' => 'default',
'search_inputs' => $search_inputs,
'autosearch' => TRUE,
'empty' => '
Nothing matched your query, sorry!
',
'query' => '
SELECT * FROM {node}
',
'columns' => array(
array(
'col' => 'nid',
'label' => 'nid',
'sortable' => TRUE,
'searchable' => TRUE,
'default_sort' => 'desc',
'help' => 'The node ID, for uniquely identifying nodes.',
),
array(
'col' => 'title',
'label' => 'Title',
'sortable' => TRUE,
'searchable' => TRUE,
'help' => 'The title of the node',
),
),
);
ajaxtable_override($table,$override);
return $table;
}
print ajaxtable_render("ajaxtable_ex2");
please help me