PEAR Forum :: PHP Extension and Application Repository

PEAR Forum Forum Index
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
[Solved] Structures_DataGrid AJAX simple example

 
Post new topic   Reply to topic    PEAR Forum Forum Index -> Structures
View previous topic :: View next topic  
Author Message
alex



Joined: 13 Sep 2006
Posts: 72

PostPosted: Fri Dec 21, 2007 11:38 am    Post subject: [Solved] Structures_DataGrid AJAX simple example Reply with quote

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
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1053

PostPosted: Fri Dec 21, 2007 1:17 pm    Post subject: Reply with quote

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
View user's profile Send private message
alex



Joined: 13 Sep 2006
Posts: 72

PostPosted: Fri Dec 21, 2007 6:18 pm    Post subject: Reply with quote

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
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1053

PostPosted: Fri Dec 21, 2007 6:42 pm    Post subject: Reply with quote

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
View user's profile Send private message
alex



Joined: 13 Sep 2006
Posts: 72

PostPosted: Fri Dec 21, 2007 7:09 pm    Post subject: Reply with quote

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
View user's profile Send private message
mark



Joined: 07 Jan 2007
Posts: 1053

PostPosted: Fri Dec 21, 2007 7:14 pm    Post subject: Reply with quote

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
View user's profile Send private message
alex



Joined: 13 Sep 2006
Posts: 72

PostPosted: Fri Dec 21, 2007 7:17 pm    Post subject: Reply with quote

Thanks a lot Mark !
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    PEAR Forum Forum Index -> Structures All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



PEAR Forum topic RSS feed 
Powered by phpBB © 2001, 2005 phpBB Group

Provided by Ministry of Web developement

'Actiemonitor' online projectmanagement software