| View previous topic :: View next topic |
| Author |
Message |
alex
Joined: 13 Sep 2006 Posts: 72
|
Posted: Fri Dec 21, 2007 11:38 am Post subject: [Solved] Structures_DataGrid AJAX simple example |
|
|
Hi !
New release (0.9.0 that I have installed) gives a simple AJAX example ; I have tried this script but it seems not working or I cannot make it work : it works as usual : it just reloads the page (and it should not I suppose) when clicking on column name to order. Same thing with the pager links.
I have placed a "alert()" in the "updateGrid()" function to try to "debug" and have no message from it.
I use Firefox and Firebug ; no errors are returned ; prototype.js is also installed.
What may I do wrong please ?
Last edited by alex on Fri Dec 21, 2007 7:10 pm; edited 1 time in total |
|
| Back to top |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1011
|
Posted: Fri Dec 21, 2007 1:17 pm Post subject: |
|
|
If AJAX paging doesn't work, you might haven't installed the latest version of Pager installed (2.4.4).
If also the sorting header links don't work, there must something else be wrong. Alex, if you look into the source code of the generated page, do the links have "onClick" attributes with calls to updateGrid()?
If you have the attributes: did you change anything besides the DSN and table name in the SQL query in this script? |
|
| Back to top |
|
 |
alex
Joined: 13 Sep 2006 Posts: 72
|
Posted: Fri Dec 21, 2007 6:18 pm Post subject: |
|
|
Thank you for your answer Mark.
I have not the "onClick" attribute in the source code. Here is my code. As you will see, it is a copied/pasten code from the example. Only dsn, js source and table name are different (of course ...).
| Code: | require_once 'PEAR.php';
require_once 'Structures/DataGrid.php';
$datagrid =& new Structures_DataGrid(10);
$options['dsn'] = 'mysql://root@localhost/b';
$datagrid->bind("SELECT * FROM users", $options);
// Set the javascript handler function for onclick events
$datagrid->setRendererOption('onMove', 'updateGrid', true);
if (isset($_GET['ajax'])) {
// Handle table AJAX requests
if ($_GET['ajax'] == 'table') {
$datagrid->render();
}
// Handle pager AJAX requests
if ($_GET['ajax'] == 'pager') {
$datagrid->render('Pager');
}
exit();
}
// No AJAX request, render the initial content..
?>
<html>
<head>
<!-- Require the Prototype JS framework from http://www.prototypejs.org -->
<script src="js/general/scriptaculous/lib/prototype.js" type="text/javascript"></script>
<script type="text/javascript">
function updateGrid(info)
{
alert("s");
var url = '<?php echo $_SERVER['PHP_SELF']; ?>';
var pars = 'page=' + info.page;
if (info.sort.length > 0) {
pars += '&orderBy=' + info.sort[0].field + '&direction=' + info.sort[0].direction;
}
new Ajax.Updater( 'grid', url, { method: 'get', parameters: pars + '&ajax=table' });
new Ajax.Updater( 'pager', url, { method: 'get', parameters: pars + '&ajax=pager' });
// Important: return false to avoid href links
return false;
}
</script>
</head>
<body>
Pages: <span id="pager"><?php $datagrid->render('Pager'); ?></span>
<div id="grid"><?php $datagrid->render(); ?></div>
</body>
</html> |
What did I miss ? Do I need a special package ? |
|
| Back to top |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1011
|
Posted: Fri Dec 21, 2007 6:42 pm Post subject: |
|
|
Did you install the new releases of the SDG_Renderer_HTMLTable and SDG_Renderer_Pager? The following line will only do something in the various renderers, if they were also updated:
| Code: |
$datagrid->setRendererOption('onMove', 'updateGrid', true);
|
|
|
| Back to top |
|
 |
alex
Joined: 13 Sep 2006 Posts: 72
|
Posted: Fri Dec 21, 2007 7:09 pm Post subject: |
|
|
Thanks Mark this was the clue.
Arghh ...
I must think to update all subpackages. Is there a way to do that in CLI ? I know "upgrade-all" does it for all packages but what for subpackages ? Is there something ? |
|
| Back to top |
|
 |
mark

Joined: 07 Jan 2007 Posts: 1011
|
Posted: Fri Dec 21, 2007 7:14 pm Post subject: |
|
|
| alex wrote: | | I must think to update all subpackages. Is there a way to do that in CLI ? I know "upgrade-all" does it for all packages but what for subpackages ? Is there something ? |
Subpackages are also normal packages and should be included in the "upgrade-all" command. The following two commands should also update both SDG and its driver:
| Code: |
pear upgrade Structures_DataGrid#datasources
pear upgrade Structures_DataGrid#renderers
|
|
|
| Back to top |
|
 |
alex
Joined: 13 Sep 2006 Posts: 72
|
Posted: Fri Dec 21, 2007 7:17 pm Post subject: |
|
|
| Thanks a lot Mark ! |
|
| Back to top |
|
 |
|