Jump to content

Ajax Datagrid


echo19

Recommended Posts

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 [url=http://www.montefili.it/dev/dg.php]www.montefili.it/dev/dg.php[/url], 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.
Now my ajax skills are zero, so i have some doubts about it...

1) Witch way to pass the data to the client?
The easier way is returning directly the whole html, row or table, the matter is the lacks on efficency, especially because the most of the times i have to reload the whole table because of sorting and paging.
Now i find difficult to pass an xml because the complexity of the data and javacript that have to deal with it but especially because i allow user to build their own custom fields...

2) I have some doubts about the page structure:
Now its something like that:
>>User.php
[code]
<HTML>
<?
require_once("DataGrid_class.php");
$dg=new DataGrid();
//$dg->Settings
?>
<?$dg->Render();?>
</HTML>
[/code]

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
[code]
<HTML>
<?
require_once("dg.php");
?>
<?$dg->Render();?>(Ajax requests to dg.php)
</HTML>
[/code]

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

b)Use sessions for settings:

>>User.php
[code]
<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>
[/code]

I almost dislike both, but if there is no other way i choose the less ugly...
What do you think is the best?

Thank you for your help
Link to comment
Share on other sites

I'm also new to Ajax, so take this for what it is worth and maybe someone else will point out where my advice is lacking.

First of all, it would help to know exactly what problem you are trying to fix.  Are you trying to overcome a connection speed issue,  server resource usage, or something else? 

The simple solution would be to send the html and use Ajax to update a <div> on a page.  There are plenty of free frameworks that will do this for you, but I cant suggest one as I am still researching them for my project. 

My overall impression is that you have the cart before the horse.  The promise and excitement around Ajax is two-fold. First, the ability to dynamically update a page (or part of a page) without a browser refresh action. The second is client side processing.  In my opinion, your datagrid should be rewritten in javascript and the php would be used to efficiently retrieve/update/create the smallest amount of data that is needed for the javascript to perform the work.  (I know thats not what you want to hear).

Link to comment
Share on other sites

Hi,
Thank you for your replay.
Yes my main aims are: easy to deploy application and reasonable execution time, both server and connection.

As you say the easiest way would be passing the whole html, but i fear its gonna be too havy....(i havent try jet), so it would be better to use xml to perform work on client side.
Now passing only xml with data is also problematic, not only because i would need tons of javascript for all that datatypes and other stuff, but i would dramaticaly have additional problems with getting all the needed settings(grafical, display..) issued ad run time by user php script, and more over it would be incompatible with custom fields etc...

I have to remark that my php script is already divided in function, so that makes easy to reply to ajax request asking for html...  ;D

For the page structure i am also a little bit confused, if you got a suggestion it would be great...i guess i'll do something like a stand-alone page istancing the class, choosing settings, defining user function and finally calling a general replay function to satisfy all kind or requests, i guess it will be a little bit slower and i will also need to costrain the navigation toolbar with the datatable, not allowing user to print it where he wants(altought it would be executed too many times!)...

Many thanks
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.