Click to See Complete Forum and Search --> : PHP-ajax Datagrid


echo19
11-18-2006, 07:43 AM
Hi,
I'm currently developing a Datagrid class to easly show, sort, filter, page and edit data rows.
You can take a look to an old verison on www.montefili.it/dev/dg.php, it works only on ie..
As soon as i finish i want to post it on phpclasses.org.
Now so far the class is almost complete, but I was wondering to move it on ajax, but my skills are zero, so i have some doubts about it but my main question is on the page structure.
Actually its something like that:
>>User.php

<HTML>
<?
require_once("DataGrid_class.php");
$dg=new DataGrid();
//$dg->Settings
?>
<?$dg->Render();?>
</HTML>

But in ajax i need a page that know all the settings but doesnt have the user grafical interface, so can reply to requests without rendering each time the unwanted html.
I can found only two ways of doing that:

a)Use a kind of configuration file (here dg.php) that replies to ajax requests, something like:

>>User.php

<HTML>
<?
require_once("dg.php");
?>
<?$dg->Render();?>(Ajax requests to dg.php)
</HTML>

>>dg.php

<?
require_once("DataGrid_class.php");
$dg=new DataGrid();
//$dg->Settings
$dg->Done();
?>
]

b)Use sessions for settings:

>>User.php


<HTML>
<?
require_once("DataGrid_class.php");
$dg=new DataGrid();
//$dg->Settings
?>
<?$dg->Render();?>(Ajax requests directly to Datagrid_class.php?datagrid_name, settings stored in session [$datagrid_name])
</HTML>
Using session have a major drawback: i cant easly use callback funtion and user defined procedure..
I almost dislike both, do you have a better idea? or what do you think is the best?


Thank you for your help

bpat1434
11-18-2006, 10:08 AM
Really, not a PHP issue, should be in ClientSide Technologies. I'll move it.

Why not just use a regular AJAXian class to send and receive an xmlHTTPRequest, then just change the content of a <div> element? Something like:

<html>
<head>
<title>My AJAX Editor</title>
<script src="/scripts/ajax.js"></script>
</head>
<body>
<div id="ajax_editor">
</div>
</body>
</html>
Now, in ajax.js you'd output all of your information and write it to the ajax_editor div with:

document.ajax_editor.innerHTML = AJAX_output;

Each request is sent to your php page, and from there PHP takes over and does the processing. Anything that you output from your PHP page should be HTML that fits in the <div> element. That seems to be the simplest solution.

Hope that helps.

echo19
11-18-2006, 11:22 AM
Sorry, it looked like a php page structure issue to me...

Anyway are you suggesting me to do something like:

user.php<HTML>
//Print javascript and html to redirect requests to dg.php
</HTML>

dg.php<?
$dg=new Datagrid();
//$dg->SETTINGS
$dg->Done();
?>

Thats almost the same as the first one but with the drawback that the dg.php is loaded some more times...making a little bit slower...
I guess that in this case i have to constrain the navigation bar to the datatable, and not allow to render it where the user prefers...

Anyway this one looks good for the 'easy to deploy', but maybe is not the best for optimization...do you have any other suggestion?

Many thanks