XML Table refresh causes Row deselection
I have a table that contains an XML table. If I select a row and then refresh the table the blue colored row selection disappears, but it is still the current selected row. Is there a way to maintain this after a refresh?
Do I just need to modify the table's response to accommodate this or is there a different way?
Thanks!
AT
March 16,
I thought I'd provide some more details/source just in case there were any questions. Below is my table and grid code:
var tblFiles = new AW.XML.Table;
tblFiles.setURL("files.xml");
tblFiles.setParameter("random", Math.random());
tblFiles.setRows("//files/*");
tblFiles.setColumns(["name", "size"]);
tblFiles.request();
var defaultResponse1 = tblFiles.response;
tblFiles.response = function(xml){
defaultResponse1.call(this, xml);
files = this.getCount();
if (curFile != ""){
grdFiles.setSelectedRows([Number(curFile)]);
}
}
var grdFiles= new AW.UI.Grid;
grdFiles.setId("grdFiles");
grdFiles.setHeaderText(["File", "Size"]);
grdFiles.setColumnCount(2);
grdFiles.setCellFormat([string, string]);
grdFiles.setSelectorVisible(false);
grdFiles.setSelectionMode("single-row");
grdFiles.setCellModel(tblFiles);
When the page loads I am starting a timeout that looks at the same files.xml and counts the rows. If there is a change I refresh the tblFiles. I am also saving the currently selected row in a variable and am trying to reselect it after the refresh. Unfortunately it isn't working. Here is the code this is running every 5 seconds:
window.onload = function (){
setTimeout("sendRequest('files.xml','POST','',statusFiles)",5000);
}
var files = 0;
var curFile = "";
function statusFiles(thisv){
if (thisv.readyState == 4) {
if (thisv.status == 200) {
var xmldoc = thisv.responseXML;
var subNode = xmldoc.documentElement;
nodeCount = subNode.childNodes.length;
if (files != nodeCount){
files = nodeCount;
if (grdFiles.getSelectedRows() != ""){
curFile = grdFiles.getSelectedRows();
} else {
curFile = "";
}
tblFiles.request();
}
setTimeout('sendRequest(\'files.xml\',\'POST\',\'\',statusMPEGFiles)',5000);
} else {
alert("Error Getting Data.");
}
}
}
If anyone can give me any hints as to why this isnt working correctly please do. Thanks!
AT
March 17,
By default the request includes a "this.$owner.clearSelectedModel();".
So it is needed a selection restore after any table.request() call.
Carlos
March 19,
Carlos,
I am running the default response and then setting the selected rows. Do you think its a timing issue? Do I need add a timeout so it can finish refreshing the grid before I set the saved rowSeletion value? Thats seems like a hack way to do it.
Thanks!
AT
March 19,
AT,
It could also be a timing issue, but I would try two more things first.
- declare 'files' & 'curFile' variables outside onload function.
- make tblFiles.request(); call after the custom response or even after the setCellModel.
sorry, not realy sure which one is ( so try them one by one ), and hope I am not overseeng the obvious and it could helps a few.
Carlos
March 19,
'files' & 'curFile' are already declared outside. Both variable values must be maintained before and after the function is called every 5 seconds.
My solution so far is this...Previously I read the tables default response into a variable and called it before I added my own custom code to the table.response. Instead, I added the code from the default response and started commenting it out to see what the cause was. Here's what I came up with:
tblFiles.response = function(xml){
this.setXML(xml);
if (this.$owner) {
this.$owner.setRowCount(this.getCount());
this.$owner.refresh();
}
files = this.getCount();
if (curFile != ""){
this.$owner.setCurrentRow(Number(curFile));
this.$owner.setSelectedRows([Number(curFile)]);
}
}
With 'clearScrollModel', 'clearSelectedModel', 'clearSortModel', and 'clearRowModel' commented out it is all working as I had planned. Someone correct me if I am wrong, but I don't feel as though I need the SelectedModel cleared when I am just going to set them again at this time. I don't want the SortModel cleared because the grid may still be sorted a certain way. The ScrollModel I probably should set so that it is either at the top or in an area where the selected row exists. But cleared every time seems like its not what I want. RowModel I am unsure of. Anyone know what exactly this would clear?
I realize that this stuff is probably good to have when the entire data set is changed, but for my purpose I think I can get away with this.
Thanks!!
AT
March 22,