:: Forum >>

ActiveWidgets Grid :: Examples with Postgres 8.1

//A SAMPLE WITH VERSION 2.0 beta4 AND POSTGRES
// damianzoanni@hotmail.com

<?php

function activewidgets_grid($name, &$data){

$row_count = @pg_num_rows($data);
$column_count = @pg_num_fields($data);


$columns = "var ".$name."_columns = [\n";
for ($i=0; $i < $column_count; $i++) {
$columns .= "\"".@pg_field_name($data, $i)."\", ";
}
$columns .= "\n];\n";

$rows = "var ".$name."_data = [\n";
while ($result = @pg_fetch_array($data)) {
$rows .= "[";
for ($i=0; $i < $column_count; $i++) {
$rows .= "\"".activewidgets_html($result[$i])."\", ";
}
$rows .= "],\n";
}
$rows .= "];\n";



$html = '<script>// create ActiveWidgets Grid javascript object
var obj = new AW.UI.Grid;

'.$rows.'
'.$columns.'


// define data formats
var str = new AW.Formats.String;
var num = new AW.Formats.Number;

//obj.setCellFormat([str, str, num, num, num]);

// provide cells and headers text
obj.setCellText('.$name.'_data);
obj.setHeaderText('.$name.'_columns);

// set number of rows/columns
obj.setRowCount('.$row_count.');
obj.setColumnCount('.$column_count.');

// enable row selectors
obj.setSelectorVisible(true);
obj.setSelectorText(function(i){return this.getRowPosition(i)+1});

// set headers width/height
obj.setSelectorWidth(28);
obj.setHeaderHeight(20);

// set row selection
obj.setSelectionMode("single-row");

// set click action handler
obj.onCellClicked = function(event, col, row){window.status = this.getCellText(col, row)};

// write grid html to the page
document.write(obj);
</script>';



return $html;
}

function activewidgets_html($msg){

$msg = addslashes($msg);
$msg = str_replace("\n", "\\n", $msg);
$msg = str_replace("\r", "\\r", $msg);
$msg = htmlspecialchars($msg);

return $msg;
}

?>


<html>
<head>
<title>ActiveWidgets Grid :: Examples</title>
<style> body, html {margin:0px; padding: 0px; overflow: hidden;} </style>

<!-- ActiveWidgets stylesheet and scripts -->
<link href="../../runtime/styles/xp/aw.css" rel="stylesheet" type="text/css" ></link>
<script src="../../runtime/lib/aw.js"></script>

<!-- grid format -->
<style>
.aw-grid-control {height: 100%; width: 100%; margin: 0px; border: none; font: menu;}
.aw-row-selector {text-align: center}

.aw-column-0 {width: 80px;}
.aw-column-1 {width: 200px;}
.aw-column-2 {text-align: right;}
.aw-column-3 {text-align: right;}
.aw-column-4 {text-align: right;}

.aw-grid-cell {border-right: 1px solid threedlightshadow;}
.aw-grid-row {border-bottom: 1px solid threedlightshadow;}
</style>



<!-- ActiveWidgets PHP functions -->

</head>
<body>

<?php

// grid object name
$name = "obj";

// SQL query
$query = "select * from \"Usuario\" ";

// database connection
$connection = pg_connect("host=192.168.10.210 port=5432 user=postgres password=123 dbname=db" );



// query results
$data = pg_query($connection ,$query);

// add grid to the page
echo activewidgets_grid($name, $data);

?>

</body>
</html>
Damian
Friday, January 27, 2006

This topic is archived.


Back to support forum

Forum search