CodeCharge Studio
search Register Login  

Visual Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> General/Other

 Seeking advice on array as grid datasource

Print topic Send  topic

Author Message
snarf


Posts: 14
Posted: 11/20/2005, 7:43 PM

I saw a number of comments about people wanting this, and one from someone who mentioned a "convoluted" way to do it...

I picked through the layers of class obstraction, and the only datasource to a grid appears to be a DB object, that's it, period, end of story.

Does anyone know of a way to use an array as a datasource for a grid? The only thing that I can come up with at this point is dumping the array to a temp heap mySQL table and creating a database object to it. In my current case, this is not a huge issue because the function at hand is rarely used, but this will not be feasible for performance reasons in other upcoming functionality.

I guess that I could just keep pushing elements onto the $Grid->Datasource->Record object on an AfterSelect event, but that seems pretty brutish...

If anyone has cooked up new classes and/or XSLT tranformations to do this in the interface, I would love to have a look (I have been into the guts of CCS to customize the interface, not squeamish).

Any and all advice from you CCS experts is appreciated! :-)
View profile  Send private message
fotrane

Posts: 13
Posted: 11/21/2005, 9:16 AM

I'm not sure if this is what you are looking for, but it seems to be similar. I wanted to have a multi-column grid, and wanted to avoid using all of the {row_open} / {row_close} as suggested in the documentation. I simply placed {catgrid} on the page, plain text (Not a label). I then entered the following in the events -> Before show page, which can easily be applied to opther pages, or even converted into a re-usable function. In the end, what I am doing is looping through an array, building an HTML table from the result, and applying that html table to a CCS template object called "{catgrid}".

global $Tpl;

// How many colums for the grid?
$columns = 2;
/////////////////////////////////////////////////////////////////////////////////////////////////////////
//Enter DB connection Data here if you aren't already connected / table //selected
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// mysql_connect('localhost','user','password');
// mysql_select_db('database');
/////////////////////////////////////////////////////////////////////////////////////////////////////////


$query = "SELECT category_id, category FROM categories ORDER BY category";
$result = mysql_query($query);
$num_rows = mysql_num_rows($result);

// Number of rows to display in the grid
$rows = ceil($num_rows / $columns);

//this loop will populate an array with all categories
while($row = mysql_fetch_array($result)) {
$data[] = $row['category_id'];
$data2[] = $row['category'];

}

/////////////////////////////////////////////////////////////////////////////////////////////////////////
// Start the HTML table
/////////////////////////////////////////////////////////////////////////////////////////////////////////
$grid .="<table width=\"100%\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\">";

for($i = 0; $i < $rows; $i++) {
$cid = $row['category_id'];
$grid .="<TR>\n";

for($j = 0; $j < $columns; $j++) {
if(isset($data[$i + ($j * $rows)])) {
$grid .="<TD><A HREF=\"yourlink.php?category=" . $data[$i + ($j * $rows)] . "\">" . $data2[$i + ($j * $rows)] . "</A></TD>\n";
}
}
$grid .="</TR>\n";
}
$grid .="</TABLE>";

/////////////////////////////////////////////////////////////////////////////////////////////////////////
// Apply the HTML to the CCS template object
/////////////////////////////////////////////////////////////////////////////////////////////////////////
$Tpl->SetVar("catgrid",$grid);



This may or may not be what you are looking for,but I hope it helps.

Happy Coding
Steve

View profile  Send private message
snarf


Posts: 14
Posted: 11/21/2005, 9:57 AM

fotrane,

Thanks for the advice. Not quite what I am looking for... what I am trying to do is use an array, not a database, for the datasource. The way to do this manually would be like:

  
  
$gridData[] = array(id=>1, firstName=>'Bob', lastName=>'Smith', title=>'CEO', officePhone=>'555-4432');  
$gridData[] = array(id=>2, firstName=>'Mike', lastName=>'Jones', title=>'CFO', officePhone=>'555-4433');  
  
echo "<table>";  
foreach($gridData AS $row => $valueArray) {  
   echo "<tr>";  
   foreach($valueArray AS $fieldName => $fieldValue) {  
      echo "<td>$fieldValue</td>";  
   }  
   echo <"/tr>";  
}  
  
echo "</table>";  
  

In my case, I have tables of information that I need people to be able to look at in a webpage and choose which records they want to import to the database. This means that I need to display the grid component with an array datatype, not a database connection object datatype. What I am looking for is a way to set the grid's DataSource to an array, and this functionality does not appear to exist. Chances are that I will end up building an empty page against the would-be receiver table, and then use a concolutes series of custom events to populate the possible values from the file() array.

Thanks for the tips -- anyone else have an ideas here?







View profile  Send private message
peterr


Posts: 5971
Posted: 11/21/2005, 11:01 AM

If the array-based grid is simple and doesn't require sorting or navigation then you could try using a label instead. Then use the Before Show event to create the whole grid on the fly and assign it as the label's value.
_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

PHP Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.