Help getting new row data for csv write.
Hi, I'm a newbie to AW, so please forgive me if this is dumb question.
After adding a row (in what seems to be a standard method taken from add/delete row example), I'm trying to write the data back to the CSV file I loaded the table from. When I do, the newly edited data is not there, and my save function writes empty fields ("") into csv. If I reload the page, then edited data in the new row is written fine.
Is there something I'm missing when it comes to refreshing the grid after a row add/delete -- perhaps something as simple as the order things occur?
I won't bother you with the process_grid.php script (which just opens the output file and write $content into it), but in my main script I'm using these functions (this happens with or without obj.refresh(); in the add() function):
Thanks!
function savegrid() {
var content=processgrid();
var filecsv="sites.csv";
save.setURL("process_grid.php");
save.setRequestMethod("POST");
save.setParameter("filename", filecsv);
save.setParameter("content", content);
save.request();
var doc="NORESPONSE";
save.response = function(doc) {
if (doc == "SUCCESS") {
document.getElementById("savebutton").disabled=true;
alert("Done \n" + filecsv + "\nnot sure of success");
}
}
}
function processgrid() {
var testIndices = obj.getRowIndices();
if (testIndices.length == 0) {
var rows = [];
for (i=0; i < obj.getRowCount(); i++) {
rows.push(i)
}
obj.setRowIndices(rows);
}
var columns = obj.getColumnCount();
var rows = obj.getRowCount();
// be sure that content is empty
content='';
for(var row=0; row<rows; row++){
var currrow='';
var currcel='';
for(var col=0; col<columns; col++){
currcel=obj.getCellText(col, row);
// fills empty cells
if (currcel=="'" || currcel=="")
currcel='""';
else
currcel='"' + currcel + '"';
// build the CSV data format
if (currrow=='')
currrow=currcel;
else
currrow=currrow + ',' + currcel;
}
content = content + currrow + '\n';
}
return content;
}
function add(){
obj.addRow(serial++);
}
function del(){
var i = obj.getCurrentRow();
obj.deleteRow(i);
}
After adding a row (in what seems to be a standard method taken from add/delete row example), I'm trying to write the data back to the CSV file I loaded the table from. When I do, the newly edited data is not there, and my save function writes empty fields ("") into csv. If I reload the page, then edited data in the new row is written fine.
Is there something I'm missing when it comes to refreshing the grid after a row add/delete -- perhaps something as simple as the order things occur?
I won't bother you with the process_grid.php script (which just opens the output file and write $content into it), but in my main script I'm using these functions (this happens with or without obj.refresh(); in the add() function):
Thanks!
function savegrid() {
var content=processgrid();
var filecsv="sites.csv";
save.setURL("process_grid.php");
save.setRequestMethod("POST");
save.setParameter("filename", filecsv);
save.setParameter("content", content);
save.request();
var doc="NORESPONSE";
save.response = function(doc) {
if (doc == "SUCCESS") {
document.getElementById("savebutton").disabled=true;
alert("Done \n" + filecsv + "\nnot sure of success");
}
}
}
function processgrid() {
var testIndices = obj.getRowIndices();
if (testIndices.length == 0) {
var rows = [];
for (i=0; i < obj.getRowCount(); i++) {
rows.push(i)
}
obj.setRowIndices(rows);
}
var columns = obj.getColumnCount();
var rows = obj.getRowCount();
// be sure that content is empty
content='';
for(var row=0; row<rows; row++){
var currrow='';
var currcel='';
for(var col=0; col<columns; col++){
currcel=obj.getCellText(col, row);
// fills empty cells
if (currcel=="'" || currcel=="")
currcel='""';
else
currcel='"' + currcel + '"';
// build the CSV data format
if (currrow=='')
currrow=currcel;
else
currrow=currrow + ',' + currcel;
}
content = content + currrow + '\n';
}
return content;
}
function add(){
obj.addRow(serial++);
}
function del(){
var i = obj.getCurrentRow();
obj.deleteRow(i);
}
Justin (Boston)
April 13,