LABKEY.DataRegions not updated after LABKEY.QueryWebPart call

LabKey Support Forum (Inactive)
LABKEY.DataRegions not updated after LABKEY.QueryWebPart call Will Holtz  2014-12-30 09:28
Status: Closed
 
I am trying to get the dataRegion corresponding to a QueryWebPart and some where it is failing silently. The LABKEY.DataRegions never gets updated to contain the new dataRegion. For a reproduction of the bug, add the following as results.html to exampleassay (or any file based assay module), and then view some results.

-Will


<div id='ResultsPartDiv'/>

<script type="text/javascript">

function init()
{
    var params = LABKEY.ActionURL.getParameters();
    var qwp1 = new LABKEY.QueryWebPart({
        schemaName: 'assay.example.' + LABKEY.page.assay.name,
        queryName: 'Data',
        filterArray: [LABKEY.Filter.create("Run/Rowid", params["Data.Run/RowId~eq"]), ],
        renderTo: 'ResultsPartDiv'
    });
    var dr = qwp1.getDataRegion();
    if (dr) {
        console.log('Got data region');
    } else {
        console.log('Could not get data region - Bug?');
    }
}

Ext4.onReady(function() {
    init();
});
</script>
 
 
Ben Bimber responded:  2014-12-30 09:31
hi will,

i think this is due to the DataRegion being loaded asynchronously. try something like:

var params = LABKEY.ActionURL.getParameters();
    var qwp1 = new LABKEY.QueryWebPart({
        schemaName: 'assay.example.' + LABKEY.page.assay.name,
        queryName: 'Data',
        filterArray: [LABKEY.Filter.create("Run/Rowid", params["Data.Run/RowId~eq"]), ],
        renderTo: 'ResultsPartDiv',
        scope: this,
        success: function(dr){
            if (dr) {
                console.log('Got data region');
            } else {
                console.log('Could not get data region - Bug?');
            }
        }
    });

and see:

https://www.labkey.org/download/clientapi_docs/javascript-api/symbols/LABKEY.QueryWebPart.html#constructor
 
Will Holtz responded:  2014-12-30 11:38
Ack! Thanks. I'm still getting used to asynchronous mindset.

-Will