Data Grid PHP Class 1.0 BETA
Wednesday, August 16, 2006Data Grid PHP Class, News
This PHP script is used to display data resulted from a MySQL query or an array, in an accessible way for the end-user.
A collection of free PHP classes that will greatly improve the quality of your PHP driven web applications while greatly decreasing the time put into writing them. Think of it as PHP Rapid Application Development. That's Zebra PHP Component Framework
This PHP script is used to display data resulted from a MySQL query or an array, in an accessible way for the end-user.
|
I am well aware of the fact that "everything has already been done" but I simply can't copy & paste other's code. I am a coder. I code. |
| Read more | |
| View my blogger profile | |
August 23, 2006 1:41 AM
Hi Stephen, this is great work. Extremely well documented - thanks.
It's exactly what I was looking for to help out a client key in some data.
The only thing that I wanted to ask is if there's a way to update the displayed row, and if the table contains no data, if there's a flag that I've overlooked to present a row's worth of empty text fields?
Thanks again!
August 23, 2006 10:04 AM
hi jeff,
i don't really understand what you mean by "update the displayed row" can you be more explicit?
as for when there's no data in the query result - you'll have it in the new version which will be available at the start of the next week.
August 27, 2006 12:14 PM
Hi Stefan. I'm trying to use your class in a project. But there is a problem. How can get contact with you? Waiting answer as soon as possible..
email: musaulker[at]gmail[dot]com
August 28, 2006 6:21 PM
just make a comment here about what you want to achieve and i'll do my best to help you and maybe we can help some other people also
August 29, 2006 5:27 PM
Stephen,
First I want to say you have done an incredible job with this datagrid class, as well as with the others listed on your blog. Excellent job! I tested your datagrid class and examples 1-3 work just fine. When I run example 4, I get a javascript error for line 640, which refers to the "addJacaScript()." Just thought you should know.
I would be happy to test any and all classes you develop. I can also give you alot of feedback on how I am using them.
I think the next thing this class needs is to allow a user to click on a record (row) with a hyperlink and be taken to an html page that gives the complete returned query in a formatted (css or template) page. Im' trying to come up with such a solution right now. I will be happy to share with you anything I come up with.
Keep up the good work!
chris
September 06, 2006 11:54 AM
thanks chris. i am most excited about you testing the classes i develop. it would really help improve their quality and usability.
please do let me know what can you achieve with the data grid class. i myself have done some nice tricks with it. :)
well, this one is just a BETA for the moment so it will have some improvements until it's final release.
thank again
September 02, 2006 6:41 PM
Hello Stefan,
I am trying to use your class and have gotten example4 to display data. However, the display does not look like the screenshot you provided (no colors, text formatting, etc.)and the following error message is displayed at the top of the page : Notice: Undefined property: javaScriptCode in /home3/dofadmin/disciplesoffaith-www/newgrid/class.datagrid.php on line 640.
Thanks
September 05, 2006 12:28 AM
Hi Stephen,
This is a great datagrid, which is exactly what I was looking for.
However I noticed a small bug when you try to put two report on the same page.
when you call: require_once $this->absolutePath."/languages/".$this->languageFile;
on a second report, the language file do not get included. I fixed it easily by replacing it by a require.
I'm also looking at adding a custom row at the end of the datagrid. This row could be used to do a sum of a column or other agregators. What do you think ?
September 06, 2006 11:59 AM
hi richard.
yes, i've never thought about putting two datagrids on the same page :)
i also thought about adding a custom row - it will be available in the final release sometime next week.
thanks for your comments
September 06, 2006 12:05 PM
hi mchtower,
there must be something wrong with how the template.xtpl file includes the stylesheet file (style.css) meaning that it can find it. that's why the data grid doesn't look like it's supposed to. when you're viewing the data grid in your browser, select "view source" and you should have a line that says "link rel="stylesheet" href="path-to-template-folder/style.css" type="text/css" where "path-to-template-folder" is probably wrong. you should edit the class.datagrid.php file, look for the line "$xtpl->assign("templatePath", $this->relativePath."/templates/".$this->template."/");" and modify it so that it will point correctly. i don't know why is not pointing correctly...
September 02, 2006 1:09 PM
I just saw and tried this yesterday. Good work. Two things:
1) Can you make the grid independent of the database driver? That is, why must it be mySQL?
2) I would like some control over the rows background colour scheme, and generally on the display fonts. Maybe these are already there but I've not seen them in the documentation.
September 06, 2006 12:08 PM
hi Raph Awoseyin,
well, indeed i made it to work only with mySQL...but i am sure you can make the necessary changes to fit whatever database - i mean there are only a few call.
as for changing fonts and colors you must edit the style.css file which is located in /templates/default/
September 26, 2006 3:11 PM
Great product, saves me a lot of work. I also get an error on line 640 with example 4 :(
Also, how would I get this working with Smarty? I've been scratching my head trying to figure that one out :P
In any case, thanks for all the effort you've put into this.
Brad
FettesPS
September 26, 2006 3:24 PM
download the file again. i've put the latest version in it with which example4 works for me. i hope it's working now
October 10, 2006 3:06 AM
Hi Stefan,
You were correct, the template path was wrong, I changed it and now all is well.
This is great work. I'm using the datagrid for a Homeowners Association website that is about to go live and have encountered no functional problems with it, I'll let you know if I find anything.
Also, I tweaked the template a bit to add a print icon which when clicked uses FPDF code to create a PDF file with the contents of the datagrid. When I'm done I can send you the modifications if you think they would be helpful.
Again, great work and thank you.
October 16, 2006 3:23 PM
Dear Stefan,
I use your datagrid but if I put 2 datagrids on the same page its interrupt each other.
I don’t understand it If you make 2 objects then it need too be independent from the other object but that isn’t . What don’t work is the custom functions for the second dategrid and sorting If I put different sorting on both grids its get corrupted.
1 datagrid on a page works fine.
Greets Joeri
October 18, 2006 10:26 AM
you are right, indeed two instances won't work on the same page. i will fix it. thanks for reporting
October 26, 2006 3:49 PM
Hello everybody,
I'm new in programming php and sql (just started to learn in the last two weeks), but this class seems very good.
I've tried to understand how to use this class through the examples, but there are lot of things which is not clear for me.
Can anybody send me other examples, small programms made with this class?
It would be very helpfull for me.
Thanks,
Norbert
hnorby@citromail.hu
November 03, 2006 12:32 PM
Hi Stefan,
You made a nice class which is very usefull. I had to made one improvement because some of my columnnames in mysql had spaces. So i changed:
ORDER BY `".$this->sortField.(strtolower($this->sortDirection) == "desc" ? "` DESC" : "`"); and now i cane sort evry column. I also noticed that sorting one grid will also sort the second grid on the same columnnumber. It would be nice if you could fix this.
Thanks
November 25, 2006 12:00 AM
hi stephan,
great class!!!
I'm very new to javascript...
I'm trying to modify example 4 so that when i clic on a line i am redirected to another page but nothing happens...
It looks like this:
function action($value_of_clicked_field, $array_with_the_values_of_all_fields_in_clicked_row)
{
return "[]";
}
can someone help me??
December 13, 2006 12:07 PM
Hi Stephan,
Great work on the datagrid, just a couple of questions
1. have you any plans to add filtering or search?
2. not really sure about the CC license, but can i redistribute this code in an open source app im working on - i wont be modifying your stuff just using it to create datagrids?
Thanks again
Cheers
Justin
justin @ kelly.org.au
December 15, 2006 9:44 AM
Hi Justin,
I plan to add A LOT of features but I just don't find the time - I have a huge text file where I write down bugs to fix and features to add and is just getting bigger all the time. Hopefully I will find the time to work on them.
Yes, you can use the class in your application as long as:
1. you tell me where I can download the application
2. you don't modify the code
3. you keep somewhere a refference to http://stefangabos.blogspot.com
December 16, 2006 4:52 PM
when I try to import the example.sql with phpmyadmin it gives an error on line 7, how else do I import the information?
December 17, 2006 8:16 AM
To fix the error:
Notice: Undefined property: javaScriptCode on line 640
Place This:
$this->javaScriptCode = "";
Under:
$this->error = "";
In:
class.datagrid.php
December 17, 2006 8:36 PM
I have implemented the class functionality to search.
It needs about one more hour of work, but the search works.
January 21, 2007 11:59 PM
Hi Stephen,
Nice work but i cant get it to work for some reason. Im using your Database class in conjunction with the Datagrid. Here is my code:
require_once "../inc/class.database.php";
require_once "../inc/inc_functions.php";
This page lists all the videos in the database. You can change the featured video and show and hide any video you have on the Youtube account.
$db = new database();
$db->debug = true;
$db->connect();
$result = $db->query("SELECT * FROM video");
/**
* The simplest way to list a query's result
* You can already
* move between pages,
* change the number of records displayed in a page
* and sort on every column
*/
// require the class
require "../inc/class.datagrid.php";
// instantiate the class and pass the query string to it
$grid = new dataGrid($result);
// show all the columns
$grid->showColumn("VideoId");
$grid->showColumn("Description");
$grid->showColumn("Enabled");
$grid->showColumn("ActiveDate");
// sort the data by the "title" column
$grid->setDefaultSortColumn("VideoId");
// witness magic!
$grid->render();
When running the script all i get is:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #6 ORDER BY VideoId LIMIT 0, 4' at line 1
Resource id #6 ORDER BY VideoId LIMIT 0, 4
January 22, 2007 12:08 AM
That's because you're not using it right! On "$grid = new dataGrid($result);" you're not supposed to pass $result as parameter but the SQL string! It should be something like:
$sql = "SELECT * FROM video";
$grid = new dataGrid($sql, &$db);
February 07, 2007 2:06 PM
Great class! I just had to change one line in the datagrid class because I was getting several STRING and L_NUMBER errors while navigating through the grid. After some research I found out it was because of some values of the columns I was showing contained single quotes (f.e. "The 80' - 90' party"). All I had to do was changing line 1029 from:
eval("\$action = ".$this->columnsToShow[$field]["action"]."('".$row[$field]."', \$row);");
to:
eval("\$action = ".$this->columnsToShow[$field]["action"]."('".addslashes($row[$field])."', \$row);");
Thanks!
February 07, 2007 2:16 PM
no, man - thank YOU!
February 14, 2007 7:12 AM
Hello Stefan,
Great class. I almost have it working the way I need it to. I added a selector column and a submit button to the grid but can't figure out how to get the submit button to process the selected rows. Any help you can provide will be greatly appreciated.
February 17, 2007 12:40 AM
Hello again Stefan,
I figured out some of what I needed to do to process selected records. In the Render function I call another function that checks to see if the submit button has been pressed and if so it will call a function that processes the selected records.
The problem I am having now is that the values for the selector column field appear to not be accessible. I added this code which outputs all available form variables :
if(isset($_POST['submit'])) {
echo '' . "\n";
print_r($_REQUEST);
echo '' . "\n";
and this is the result :
Array
(
[dataGrid_page] =>
[dataGrid_sortfield] => lastname
[dataGrid_sortdirection] =>
[dataGrid_recordsOnPage] => 15
[submit] => Register
)
When I view the source for the page that outputs the grid I see that the show selector column has a name associated with it but I can't figure out why the values for it can not be accessed.
February 21, 2007 4:38 PM
Stefan,
I figured out the previous problem. I'm not sure if this is by design but if the user makes no selections the array that holds selections is not created and therefore cannot be examined. I got around this by checking to see if the key for the selection array exists in $_REQUEST like this :
if (array_key_exists('check', $_REQUEST).
If there a more efficient way to do this?
February 23, 2007 5:49 PM
function action($value_of_clicked_field, $array_with_the_values_of_all_fields_in_clicked_row)
{
return "javascript:window.location.href('Delete_Feedback.php?FId=". $array_with_the_values_of_all_fields_in_clicked_row["FId"]."')";
}
Could anyone help regarding this???
It works in IE but when i test in Mozilla,it can't works.Thanks!
March 07, 2007 4:55 AM
Peck,
I'm trying to figure out why your function does not work in Mozilla, so far I'm stumped. I have noticed that javascript sometimes cause errors in the grid. For example, I'm also trying to figure out why adding a button with a javascript function is causing the grid paging functions to produce javascript errors. I will let you know if/when I find a solution to your problem.
March 19, 2007 5:40 AM
Thanks Michael!
February 23, 2007 5:48 PM
Can somebody help me regarding this
function action($value_of_clicked_field, $array_with_the_values_of_all_fields_in_clicked_row)
{
return "javascript:window.location.href('Delete_Feedback.php?FId=". $array_with_the_values_of_all_fields_in_clicked_row["FId"]."')";
}
if works in IE,but can't work in Mozilla when i try to click on the row.
July 15, 2008 10:29 AM
Hi Stephan!!
Thanks for this great class.
I run into some problems .
I am using chcekboxes .I get options check all etc.
This works fine.But in case i out my grid inside a form, on clicking check all..etc.. it goes to another page.
say for example my current page is http://10.31.45.46/xampp/abc.php" , on clicking it goes to http://10.31.45.46/xampp
How can i get rid of this problem?
July 15, 2008 3:29 PM
the problem is that the grid itself is a form...and therefore you have nested forms which is what causing your problems. you could add your controls to the grid's form by using the setHeaderHTML() method.
July 16, 2008 9:33 AM
Thanks stephan!!
I am aware of the setHeaderHTML() method,but I have already worked around the problem.
I have another issue, with each row (from my databse), i want to display an aditional field that is not in the database . This is a gif image and will vary from row to row.
I tried using showCustomColumn and setColumnHTMLProperties to display a gif image in all the rows.But i need different gif image in different rows.
How to do that?