Refresh doesnt work?!?!?
OKay, I know I have gotten refresh to work previously but it certainly is not working now....
I am building a stress testing tool to hit an XMLRPC listener, and am using the grid to define test cases to post to the listener.
This is all internal so security of the db is not a concern, that being said I am building a grid based upon a mysql table and giving people the ability to edit cells and create new rows (by way of a mysql helper script).
I have no problem editing/saving the data or inserting new rows, however the obj.refresh() call doesnt work....
The only thing I can think of is a caching/timing problem...but I know I have gotten it to work previously....
Banging my head pretty good on this one!
here is my code:
<?php
include 'config2.php';
include 'dbconnect.php';
$dataset = mysql_query("SELECT * FROM txtable ORDER BY id ASC");
// print MySQL query results as 2D javascript array
function aw_cells($dataset){
$rows = array();
while ($record = @mysql_fetch_row($dataset)) {
$cols = array();
foreach ($record as $value) {
$cols[] = '"'.addslashes($value).'"';
}
$rows[] = "\t[".implode(",", $cols)."]";
}
echo "[\n".implode(",\n",$rows)."\n];\n";
}
// print MySQL field names as javascript array
function aw_headers($dataset){
while ($field = @mysql_fetch_field($dataset)) {
$cols[] = '"'.$field->name.'"';
}
echo "[".implode(",",$cols)."];\n";
}
?>
<html>
<head>
<!-- include AW stylesheet and script -->
<link href="ActiveWidgets/runtime/styles/xp/aw.css" rel="stylesheet" type="text/css" ></link>
<script src="ActiveWidgets/runtime/lib/aw.js"></script>
</head>
<body>
<script>
// insert javascript arrays produced by PHP functions
var myHeaders = <?= aw_headers($dataset) ?>
var myCells = <?= aw_cells($dataset) ?>
// create grid control
var obj = new AW.UI.Grid;
obj.setSize(1000, 400);
// set grid text
obj.setHeaderText(myHeaders);
obj.setCellText(myCells);
// set number of columns/rows
obj.setColumnCount(myHeaders.length+1);
obj.setRowCount(myCells.length);
// Make the grid editable
obj.setCellEditable(true);
// write grid to the page
obj.setColumnIndices([0,1,2,3,4,5,6,7,8,9]);
document.write(obj);
// Handle Edits, POST the row up as an sql update
obj.onCellValidated = function(text, column, row){
mine = obj.getCellText(column, row);
var r = new AW.HTTP.Request;
r.setURL("updateSingleCell.php");
r.setRequestMethod("POST");
r.setParameter("type", "update");
r.setParameter("id", obj.getCellText(0,row))
r.setParameter("txType", obj.getCellText(1,row))
r.setParameter("txID", obj.getCellText(2,row))
r.setParameter("cHolder", obj.getCellText(3,row))
r.setParameter("eMail", obj.getCellText(4,row))
r.setParameter("txAmount", obj.getCellText(5,row))
r.setParameter("cNumber", obj.getCellText(6,row))
r.setParameter("eDate", obj.getCellText(7,row))
r.setParameter("language", obj.getCellText(8,row))
r.request();
r.response = function(data){
// alert(data); // process response data
}
}
// Handle Adding a row, POST to the mysql helper php with an insert of dummy data
function add(){
//alert('lets add a row');
var r = new AW.HTTP.Request;
var row = "1";
r.setURL("updateSingleCell.php");
r.setRequestMethod("POST");
r.setParameter("type", "add");
r.setParameter("id", "Null")
r.setParameter("txType", "txType")
r.setParameter("txID", "txID")
r.setParameter("cHolder", "cHolder")
r.setParameter("eMail", "eMail")
r.setParameter("txAmount", "txAmount")
r.setParameter("cNumber", "cNumber")
r.setParameter("eDate", "eDate")
r.setParameter("language", "language")
r.request();
r.response = function(data){
// alert(data); // process response data
//try and refresh here maybe the data isnt available?
obj.refresh();
}
//try and refresh here maybe the data isnt available?
obj.refresh();
}
function refresh(){
//okay I should be able to arbitrarily refresh the table any time with this!
obj.refresh();
}
</script>
<button onclick="add();refresh()">add row</button>
<button onclick="refresh()">refresh</button>
</body>
</html>
I am building a stress testing tool to hit an XMLRPC listener, and am using the grid to define test cases to post to the listener.
This is all internal so security of the db is not a concern, that being said I am building a grid based upon a mysql table and giving people the ability to edit cells and create new rows (by way of a mysql helper script).
I have no problem editing/saving the data or inserting new rows, however the obj.refresh() call doesnt work....
The only thing I can think of is a caching/timing problem...but I know I have gotten it to work previously....
Banging my head pretty good on this one!
here is my code:
<?php
include 'config2.php';
include 'dbconnect.php';
$dataset = mysql_query("SELECT * FROM txtable ORDER BY id ASC");
// print MySQL query results as 2D javascript array
function aw_cells($dataset){
$rows = array();
while ($record = @mysql_fetch_row($dataset)) {
$cols = array();
foreach ($record as $value) {
$cols[] = '"'.addslashes($value).'"';
}
$rows[] = "\t[".implode(",", $cols)."]";
}
echo "[\n".implode(",\n",$rows)."\n];\n";
}
// print MySQL field names as javascript array
function aw_headers($dataset){
while ($field = @mysql_fetch_field($dataset)) {
$cols[] = '"'.$field->name.'"';
}
echo "[".implode(",",$cols)."];\n";
}
?>
<html>
<head>
<!-- include AW stylesheet and script -->
<link href="ActiveWidgets/runtime/styles/xp/aw.css" rel="stylesheet" type="text/css" ></link>
<script src="ActiveWidgets/runtime/lib/aw.js"></script>
</head>
<body>
<script>
// insert javascript arrays produced by PHP functions
var myHeaders = <?= aw_headers($dataset) ?>
var myCells = <?= aw_cells($dataset) ?>
// create grid control
var obj = new AW.UI.Grid;
obj.setSize(1000, 400);
// set grid text
obj.setHeaderText(myHeaders);
obj.setCellText(myCells);
// set number of columns/rows
obj.setColumnCount(myHeaders.length+1);
obj.setRowCount(myCells.length);
// Make the grid editable
obj.setCellEditable(true);
// write grid to the page
obj.setColumnIndices([0,1,2,3,4,5,6,7,8,9]);
document.write(obj);
// Handle Edits, POST the row up as an sql update
obj.onCellValidated = function(text, column, row){
mine = obj.getCellText(column, row);
var r = new AW.HTTP.Request;
r.setURL("updateSingleCell.php");
r.setRequestMethod("POST");
r.setParameter("type", "update");
r.setParameter("id", obj.getCellText(0,row))
r.setParameter("txType", obj.getCellText(1,row))
r.setParameter("txID", obj.getCellText(2,row))
r.setParameter("cHolder", obj.getCellText(3,row))
r.setParameter("eMail", obj.getCellText(4,row))
r.setParameter("txAmount", obj.getCellText(5,row))
r.setParameter("cNumber", obj.getCellText(6,row))
r.setParameter("eDate", obj.getCellText(7,row))
r.setParameter("language", obj.getCellText(8,row))
r.request();
r.response = function(data){
// alert(data); // process response data
}
}
// Handle Adding a row, POST to the mysql helper php with an insert of dummy data
function add(){
//alert('lets add a row');
var r = new AW.HTTP.Request;
var row = "1";
r.setURL("updateSingleCell.php");
r.setRequestMethod("POST");
r.setParameter("type", "add");
r.setParameter("id", "Null")
r.setParameter("txType", "txType")
r.setParameter("txID", "txID")
r.setParameter("cHolder", "cHolder")
r.setParameter("eMail", "eMail")
r.setParameter("txAmount", "txAmount")
r.setParameter("cNumber", "cNumber")
r.setParameter("eDate", "eDate")
r.setParameter("language", "language")
r.request();
r.response = function(data){
// alert(data); // process response data
//try and refresh here maybe the data isnt available?
obj.refresh();
}
//try and refresh here maybe the data isnt available?
obj.refresh();
}
function refresh(){
//okay I should be able to arbitrarily refresh the table any time with this!
obj.refresh();
}
</script>
<button onclick="add();refresh()">add row</button>
<button onclick="refresh()">refresh</button>
</body>
</html>
Desmund
February 16,