Dynamic table query
| Project: | Ajax Table |
| Version: | 5.x-1.2 |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
We have a requirement where we need to list no just nodes, but non-node table records that are related to one particular node (in this case, the list of users signed up for an event: these are records in the signup_log table).
However, currently, the query used to retrieve data is static relative to the ajaxtable_table_, in the sense that is cannot be changed. So the nid of the node currently being displayed cannot be passed to the query.
At the same time, there is a $uid variable passed to the ajaxtable_render method, which is then set as $table['uid'] in the _ajaxtable_render method. However, this is too late to affect the query, because by then the table is already constructed. (note: naming this variable 'uid' is very confusing).
The documentation also shows usage of the ajaxtatble_table_ function being defined as:
function ajaxtable_table_<id>($override = '') { ... }
however it doesn't look like the $override parameter is used anywhere (even in the docs' examples, despite appearances)
I venture to make the following sugestion: use the $uid parameter to make the table definition dynamic at the time of creation. The $uid parameter can be passed to the ajaxtable_table_ function and b used by it to generate the proper settings for the table.
function ajaxtable_render($id, $uid, ..) {
...
$function_name = 'ajaxtable_table_' . $id;
...
$table = $function_table($uid);
...
}The ajaxtable_table fucntion can then be defined as:
function ajaxtable_table_id1($uid = '') {
$table = array(
'query' => _get_sql($uid),
'columns' => ...
);
return $table;
}As far as I can see, this code seems compatible with the table override mechanism, at least the way it is implemented.
function ajaxtable_table_id2($uid = '') {
$override = array(...);
$table = ajaxtable_table_id1($uid);
ajaxtable_override($table, $override);
return $table;
}