3.2.0

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>

Desmund
February 16,
Where u parse the xml to grid?
I can't see why grid should change.

Example:
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.request( );
r.response = function(xml) {
   // get value, whatever...
    var value = xml.getElementsByTagName(.....)....nodeText;
    obj.setCellText( value, 0, 2);
    obj.refresh( ); // nice, now u have an modification.
  
}
Pc (from Brazil)
February 16,
I am not using raw XML, we are parsing a mySQL query from the DB and buildind the array based upon the table data.

I am using helpers to handle DB manipulation (add, delete, insert) and need to have the table updated to reflect the state of the DB....I suppose we could update the grid without hitting the DB but I want to make sure that the information is 100% real...IE what is exactly in the DB, incase there was a connectivity issue or such.

I managed to work around this however though it is not even close to what I want to do:

where I pass refresh("0") if I want to try and reload the grid or refresh("1") if I want to reload the page completely.

function refresh(mode)
{
if (mode=="0")
{
logger('reloading the page with mode: '+mode, "1");
obj.refresh();
}
else
{
//ouch refresh isnt working like I thought it would,
//lets just go ahead and reload the whole page!
logger('reloading the page with mode: '+mode, "1");
window.location.reload();
}
}

This does the job but now I have to work on passing the state of the toggles that I am allowing on the grid (multi-select, editable, etc), so that the user doesnt lose the state that they have setup inbetween refreshes.

I looked into the many other things that you can refresh:

obj.clearScrollModel();
obj.clearSelectionModel();
obj.clearSortModel();
obj.clearSelectionModel();
obj.refresh();

but still none of these seemed to get my view to update after:

adding a row to the db
toggling mult-row-select
deleting a row from the db

I can survive with things as is, but would really-really love the right solution....................
Desmund
February 22,
hit the f5 key it works
October 25,

This topic is archived.

See also:


Back to support forum