Jump to content

test my data grid, its so easy i named it EZGrid


s0c0

Recommended Posts

I didn't think any of the existing datagrids out there where simplistic enough so I created my own.  I'm still developing but I feel its at a point to get some feedback on it.

 

Download it here http://blog.cnizz.com/ezgrid.zip

 

The zip archive contains the class (C_EZGrid.php), the css file (ezgrid.css), 2 images, and the view page (ezgrid.php).

 

Here are the steps to using it:

1. download the file to your web server.

2. the zip archive contains everything you will need to test it out.

3. use this example:

 

<?
include_once('/php/global/C_EZGrid.php');
$db = 'database connection' // this your database connection link which is needed by mysqli

$gridObj = new C_EZGrid('users',$db); // construct the object
$gridObj->set_sql('SELECT id,username,city,state,country,joined,lastLogin FROM users'); // set the sql (replace with your own)
$gridObj->opt_left_arrow='arrow-left.gif'; // set image
$gridObj->opt_right_arrow='arrow-right.gif'; // set image
$gridObj->set_column_names(array('ID','User','City','State','Country','Joined','Last Login')); // replace with your own custom column names
//$gridObj->debug(); # uncomment this line to get debugging info
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>EZ Grid Demo</title>
<link rel="stylesheet" href="ezgrid.css" type="text/css" />
</head>
<body>
<?=$gridObj->display_grid(); ?>
</body>
</html>

 

4. In the above example you include the C_EZGrid class.

5. I pass the table name (users) and the database connection link to C_EZGrid's constructor.

6. Next I set my sql statement (optionally you can pass in an array instead using $gridObj->set_dataArr($array_name) ).

7. I can then set my right and left arrow images (these were included in the zip archive).

8. Now I set the column names for my html table header by passing them in as an array.  If you don't specify these it will use the actuall column names defined in your mysql table.

9. Now I can call $gridObj->display_grid() which will return text and when you echo the text you get a pretty table!

 

If you run into problems you can try $gridObj->debug() and see if the debug info helps.  There are more options you can set but I didn't feel like writing them all out, the code is pretty well commented, basically if its a public data member you can set it to your liking.  The opt_detailsArr is pretty cool as it lets you make all values in a column linkable for administration of that row.  For instance I could do this:

 

$gridObj->opt_detailsArr=array('id'=>array('details','id'));

 

This would make all the ID fields link to the current page with the url parameter of details= [whatever the id is].

So it would look like this <a href="ezgrid.php?details=5">5</a> and so on...

 

Anywho let me know what you think and if you have any suggestions.

Link to comment
Share on other sites

  • 1 month later...
×
×
  • 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.