Problem refreshing the table
victorwong - January 4, 2008 - 11:11
| Project: | Ajax Table |
| Version: | 5.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
Description
I have installed drupal in the sub folder drupal-5.5/ and then call the ajxtable - ajaxtable_table_ajaxtable_example1 from my own develop module. The table can be display and it looks great. However, I cannot trigger the sort function. Whenever I click the up or down arrow, it popup "There was a problem refreshing the table. Please try again". Not to mention the update. Can anybody help me solve this problem? Many thanks.

#1
I'm having the same issue. It pages fine, but the sort is blank. I have inspected the AJAX and it does return something, but it isn't getting assigned. I'll see if I can work it out.
#2
I have uploaded a fix to the problem. Is was a place where I was using an absolute URL instead of the url() function in the javascript function that processes the re-sorting. The CVS dev should be current, and I have also created an official release so it's easier to track patches (it's DRUPAL-5--1-0).
#3
I had to fix mine with this patch.
It checks the SQL query for ORDER BY that might already be there.
I fixed a couple of other places where a Search would break it as well.
And FYI, searching by profile fields for a user does not really seem possible if you are doing multiple fields.
#4
lubtex: A couple of questions:
1. What were the other changes you made to allow ORDER BY with the search functionality?
2. In regards to the profile field comment, you should be able to search by profile fields as long as your query grabs the fields.
I wonder if it would be useful to include functionality to create a table that grabs all user and profile information by default.
#5
1 - What I did was instead of just appending the where sql to the end of the query, I tested the query for the order by.
2 - Here is the query I'm using to pull in profiles:
SELECT u.*, sch.value AS school, dist.value AS district, reg.value AS region, exp.value AS expire FROM users AS u, profile_values AS sch, profile_values AS dist, profile_values AS reg, profile_values AS exp WHERE sch.fid=2 AND dist.fid=3 AND reg.fid=6 AND exp.fid=5 AND u.uid=sch.uid AND u.uid=dist.uid AND u.uid=reg.uid AND u.uid=exp.uid ORDER BY u.created DESCWhen I try to do a search on one of the profile fields it makes the query like this
SELECT u.*, sch.value AS school, dist.value AS district, reg.value AS region, exp.value AS expire FROM users AS u, profile_values AS sch, profile_values AS dist, profile_values AS reg, profile_values AS exp WHERE sch.fid=2 AND dist.fid=3 AND reg.fid=6 AND exp.fid=5 AND u.uid=sch.uid AND u.uid=dist.uid AND u.uid=reg.uid AND u.uid=exp.uid AND (name LIKE '%%%s%' OR school LIKE '%%%s%' OR district LIKE '%%%s%' OR region LIKE '%%%s%' OR expire LIKE '%%%s%') ORDER BY u.created DESCThat generates a sql error for me saying unknown column 'school' in the where statement. It would only find it if it was sch.value.
I suppose you could create an out of the box way to do profiles, but I can do without searching on those profile fields for my application.
#6
In regards to 1), I was asking because it seemed like the patch was incomplete. It did the check for ORDER BY, but broke on searching. I was wondering if you could post the full patch that fixed the ORDER BY in the search as well.
In regards to 2) With your ajaxtable declaration function, are you using the 'alias' parameter in your columns (the docs cover this, I think)? I know that was the only I could get certain columns to work properly when using aliases.
#7
I think I updated the uploaded patch since you looked at it.
The alias is documented, but it isn't implemented in the search queries. Attached is a patch to fix that. Thanks for the heads up.
#8
The new release has fixed the sorting problem. But cannot update records in example 4, an warnning message "There was a problem processing your request. Please try again." No matter which rows I click, the cursor always goes to the last row and then warning popup. I am using IE 6. How should I solve this error? Thanks.
#9
You might take a look at the other open issue that me and stompeers have been working on. I think it might apply to you as well. I think it might have to do with IE attributing things to the last ID instead of the first ID on the page.
http://drupal.org/node/206419
#10
I have tested and applied the ORDER BY patch, thank you lubtex. However, the alias.patch doesn't seem to work for me. I don't know if this is because I've changed something else or not. Currently, aliases seem to work just fine in the search box, but that breaks if I add your patch. Can you give the latest dev version a try when a new snapshot is released?
#11
Here is one solution for searching for and displaying profile info. This code may be a little quirky because it has a specific use, but it works well for me:
In my ajaxtable, I have the following parameters (note that this selects all users with a particular permission. In my case, it's a list of clients):
function ajaxtable_table_mymodule_clients($override='') {$table = array(
'rows' => 100,
'user_edit' => TRUE,
'user_delete' => TRUE,
'query' => '
SELECT DISTINCT u.* FROM {role} r, {users_roles} ur,
{permission} p,
{users} u
LEFT JOIN {profile_values} pv ON u.uid = pv.uid LEFT JOIN {profile_fields} pf ON pv.fid = pf.fid
WHERE
u.uid = ur.uid AND
ur.rid = r.rid AND
r.rid = p.rid AND
p.perm LIKE "%%mymodule client view%%" AND
u.name != "admin"
',
'count_query' => 'DISTINCT u.uid',
'columns' => array(
array(
'col' => 'u.uid',
'label' => 'UID',
'sortable' => TRUE,
'searchable' => TRUE,
'input_value' => TRUE,
'unique' => TRUE,
'default_sort' => 'desc',
'help' => 'The user\'s unique ID',
),
array(
'col' => 'u.name',
'label' => 'Username',
'sortable' => TRUE,
'searchable' => TRUE,
'help' => 'The username of the user',
),
array(
'col' => 'pv.value',
'label' => 'Profile',
'sortable' => TRUE,
'searchable' => TRUE,
'callback' => 'projectm_col_profile',
'help' => 'Details about the user, if available, including their address and full name.',
),
),
);
ajaxtable_override($table,$override);
return $table;
}
And then I have the following for the profile column function:
function mymodule_col_profile($col,$value,$row,$table,$callback_array) {global $profile_map;
if (!$profile_map) {
$sql = 'SELECT name,title FROM profile_fields';
$result = db_query($sql);
while ($prow = db_fetch_array($result)) {
$profile_map[$prow['name']] = $prow['title'];
}
}
$user = new StdClass();
$user->uid = $row['uid'];
profile_load_profile($user);
foreach($user as $key=>$value) {
if ($key != 'uid' && $value != '') {
$content .= '<tr><td style="text-align:right"><strong>' . $profile_map[$key] . '</strong>: </td> <td>' . $value . '</td></tr>';
}
}
if ($row['mail']) {
$content .= '<tr><td style="text-align:right"><strong>E-mail:</strong>: </td> <td><a href="mailto:' . $row['mail'] . '">' . $row['mail'] . '</td></tr>';
}
return '<table>' . $content . '</table>';
}
#12
Here the alias patch again against the latest 1.3.2.2 from CVS - I can't get aliases to work with out it.
As far as the profile, I don't think its worth it to try to have a cookie cutter solution, as each site uses them so differently, for example, your code wouldn't work very good for me since many of my users have multiple roles. Also, I need to search on multiple profile fields.