i have a button attached to a query. this button can result in updates to rows show in the dataregion. therefore in the onSuccess() callback for that call to updateRows(), I'd like to force the dataregion to refresh itself. this is a labkey dataregion, not an ext editorGridPanel.
the button's handler is vaguely like this:
function markComplete(dataRegion, menu, schemaName, queryName){
//capture user input then build an array of the rows to be updated. code omitted for simplicity
//then call updateRows()
LABKEY.Query.updateRows({
schemaName: schemaName,
queryName: queryName,
rows: toUpdate,
scope: this,
success: function(){
Ext.Msg.hide();
//and here i'd like to force a refresh of the dataregion.
//the function markComplete() is passed a reference to the dataregion, so we can operate on that
},
failure: EHR.utils.onError
});
}
i am reading DataRegion.js. Unless I'm missing something, there is some obvious, shared 'refresh' method. I could do something like set the view of the dataregion to the currently selected view, or combine changeSort() and getUserSort() to change the sort of the same sort that is currently used (ie. trigger a reload without actually changing anything). i have not fully researched whether any of these would capture all the possible user-applied filters/sorts though.
what's the best to force a refresh of the dataregion for the purpose of reloading data, without changing anything else?
thanks in advance. |
|
kevink responded: |
2011-06-14 13:15 |
I think you can use a QueryWebPart and call the render() function. The DataRegion doesn't track the user applied sorts/filters so won't be able to refresh itself. I would like to teach DataRegion how to refresh itself but it requires some server-side work. |
|
Ben Bimber responded: |
2011-06-15 03:08 |
hi kevin,
thanks for the reply. one of the more compelling reasons to attach a button to a query is so that button and its code gets carried through the labkey UI wherever that query shows up without needing to build and maintain the UI associated with embedding a QWP in an html page. the latter solves the problem in one situation and it is quite easy in labkey user the user to be taken to some other page that might show your query (ie. anything using executeQuery).
it still seems that faking the user action of applying a sort really ought to do the same thing i'm trying to do. when you apply a filter or a sort, the dataregion does refresh. that is initiated by client-side JS code. |
|
kevink responded: |
2011-06-15 12:31 |
Well, DataRegion can't refresh in place on the page -- the whole page must be refreshed by changing the URL when a sort/filter changes. If the filter and sort aren't changing, can you just refresh the entire page using window.location.reload()? |
|
Ben Bimber responded: |
2011-06-15 12:41 |
hi kevin,
maybe i have my labkey terminology off. i was under the impression that dataRegion referred to the labkey grid itself. a QWP is the wrapper around a dataRegion that is used if you embed a dataregion in a page. if you're loading executeQuery.view, this page has a dataregion, but no QWP. is this correct?
so perhaps i should alter the question. what i'd ideally like to figure out is some sort of code that i can put in a button handler that can execute and refresh the associated labkey grid, whether it is loaded via executeQuery.view or whether it is loaded using a QWP embedded in some other page. it could well be that 2 distinct paths are needed; however, the code would need some mechanism to figure out the context of the current grid and which path to execute. you are correct that if executeQuery is used, you could just refresh the page.
-the code could use LABKEY.ActionUrl to figure out what the current page is. if it's executeQuery.view, then it would trigger a page reload.
-if it's not executeQuery.view, then we assume it's embedded and we want to use AJAX. is there a good mechanism to obtain a reference to the associated QWP? as far as i can tell, the button handler is passed a reference to the dataregion only, and not directly a reference to the QWP. does a dataregion that is part of a QWP have a reference to that QWP? what about the reverse?
thanks. |
|
kevink responded: |
2011-06-15 15:13 |
You're right -- the QueryWebPart is a wrapper that you can use to embed a DataRegion grid in a page. When using the executeQuery.view action, there is no QueryWebPart wrapper around the DataRegion -- it is rendered directly into the page.
You're also right that the DataRegion doesn't have a reference to the QueryWebPart that 'owns' it. You may be able to use a the QueryWebPart's success callback to stash a reference to the QueryWebPart on the DataRegion. Your button handler could then look for the reference and call .render() on the QueryWebPart or refresh the entire page if there is no reference. I haven't tried this so I don't know how well it will work. |
|
Ben Bimber responded: |
2011-06-15 16:02 |
|
|
|
|