getting row content from dojo.gridx it always shows the old data initially loaded

3.1k views Asked by At

I'm trying to retrieve the data values stored in a dojo.gridx table as the relevant row is clicked. It works fine as long as the following function is called the first time, when that function is called again with new data, then those data appear correctly at the screen but as I click any row the actual data retrieved are the ones belonging to that row holding the data loaded the first time the function was called. The only way to get the correct data is to reload the entire html page calling the java script. The data loaded as 'dati' come dynamically from a ajax-js not shown here.

HTML reference:
<table data-dojo-type="gridx.Grid" id="userconf" selectable="true"  selectionMode="single" singleClickEdit="true" style="width: 936px; position: absolute; z-index: 900; left: 23px; top: 280px; height: 170px;" data-dojo-props="cacheClass: 'gridx/core/model/cache/Async',store:ItemFileWriteStore_11">
<thead>
   <tr>
     <th field="cf_utente" width="auto" editable="true" type="dojox.grid.cells.Bool">
      cf_utente</th>
     <th field="sn_contatore" width="auto" editable="true" type="dojox.grid.cells.Bool">
      sn_contatore</th>
     <th field="sn_serbatoio" width="auto" editable="true" type="dojox.grid.cells.Bool">
       sn_serbatoio</th>
     <th field="seqnum" width="auto" editable="true" type="dojox.grid.cells.Bool">
       seqnum</th>
    </tr>
 </thead>
</table>

jscript:

function fillupAnagUsers(dati) {
var grid = dijit.byId('userconf');
var rows = dati.split("\n");
var righe = [];
var data = {items: righe};
var i,j,rw,x;
var lbl = rows[0].split(",");
var newStore = new dojo.data.ItemFileWriteStore({data: data});
for(i=1;i<rows.length-1;i++) {
    rw = rows[i].split(",");
    x = "{";
    for(j=0;j<lbl.length-1;j++) {
        x +=lbl[j]+":\""+rw[j]+"\",";
    }
    x += lbl[j]+":\""+rw[j]+"\"}";
    eval('var obj='+x);
    data.items.push(obj);
}

grid.setStore(newStore);

var handle = dojo.connect(grid, "onCellClick", grid, function(evt){

        var idx = evt.rowIndex;
    var data = this.cell(idx, 0).data();
    dojo.byId('cfutente').value = data.substring(data.indexOf('r>')+2,data.indexOf('</'));
    data = this.cell(idx, 1).data();
    dojo.byId('sncontatore').value = data.substring(data.indexOf('r>')+2,data.indexOf('</'));
    data = this.cell(idx, 2).data();
    dojo.byId('snserbatoio').value = data.substring(data.indexOf('r>')+2,data.indexOf('</'));
    data = this.cell(idx, 3).data();
    dojo.byId('useqnum').value = data.substring(data.indexOf('r>')+2,data.indexOf('</'));
    dojo.byId('rec').value = dojo.byId('useqnum').value;


});

 }
1

There are 1 answers

0
Danubian Sailor On

GridX need identifier:

var data = {items: righe, identifier: 'myidfield'};

Setting the store is not enough, you need also to clean the cache and force refresh of grid content:

            grid.model.clearCache();
            store = new Memory({data: data});
            grid.model.setStore(store)
            grid.body.refresh()