3.2.0

XML data refresh bug when sorted descending in 2.0.1

I'm having an issue with refreshing XML data in the grid while there is a descending sort in place.

In the following example, if you sort by column 0 ascending and click the "changedata" button, everything works correctly.

But, if you start over and sort by column 0 descending, the grid only shows the data for 2 of the rows. The new grid count is correct, but the data is blank for most rows.

This only seems to happen if the number of rows changes.

Anybody know of a work around?


<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: 200; 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;}
    </style>
</head>
<body>
    <input type="button" value="changedata" onclick="changeData()" />

    <script>
    
    var count = 0;
    function getXml(rowCount, extra){
        if(!extra){
            extra = "";
        }
        var xml = "<data>";
        for(var row=0;row<rowCount;row++){
            xml += "<row>";
            for(var col=0;col<5;col++){
                xml += "<col"+col+">" + extra +  + row + ","+  col + "</col"+col+">"  ;
            }
            xml += "</row>";
        }
        xml += "</data>";
        return xml;
    }
    
    
    
    function getDocumentFromString(xmlString){
        //	IE
        if (window.ActiveXObject) {
            var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
            xmlDoc.async="false";
            xmlDoc.loadXML(xmlString);
            return xmlDoc;
        }
        //	Mozilla
        else {
            return new DOMParser().parseFromString(xmlString, "text/xml");
        }
    }
    
    
    function changeData(){	 
        table.setXML( getDocumentFromString(getXml(6, "change " + count + " " )) );
        count += 1;
        obj.setRowCount(table.getCount());
        obj.refresh();
    }
    
    var obj = new AW.UI.Grid;
    obj.getHeaderText =  function (i) {return  "Column " + i };
    
    var table = new AW.XML.Table;
    table.setColumns( ["col0","col1","col2","col3","col4"]);
    table.setXML( getDocumentFromString(getXml(10)) );
    obj.setCellModel(table);
    
    obj.setRowCount(table.getCount());
    obj.setColumnCount(5);
    obj.setSelectionMode("single-row");
    document.write(obj);

    </script>
  
</body>
</html>






Mike Graessle
August 7,
Mike, I'm not really sure ( and wolud preffer that Alex confirm/clarify it )
, but I think it is related to:
/javascript.forum.11480.5/refresh-content-in-grid.html
After a few testing, clearRowModel() seems to do the trick.

function changeData(rows){
obj.clearRowModel();
table.setXML( getDocumentFromString(getXml(rows, "change " + count + " " )) ); 
count += 1; 
obj.setRowCount(table.getCount()); 
obj.refresh(); 
 }

Carlos
August 7,
Sorry Mike, that breaks the sort order ( So less sure than before), but if this is the right workaround ??? then, re-sort is needed:
function changeData(){  
var i = obj.getSortColumn(); 
var idir = obj.getSortDirection(i);
obj.clearRowModel();
table.setXML( getDocumentFromString(getXml(6, "change " + count + " " )) ); 
count += 1; 
obj.setRowCount(table.getCount()); 
obj.sort(i, idir);
//obj.refresh(); 
 }
Carlos
August 7,
Thanks Carlos. That seems to fix the issue, while preserving the sort order.
Mike Graessle
August 8,

This topic is archived.

See also:


Back to support forum