How can one interact with a QueryWebPart via JS ?

LabKey Support Forum
How can one interact with a QueryWebPart via JS ? Leo Dashevskiy  2014-08-20 12:08
Status: Closed
 
Hello, folks!

I'm interested in the following scenario:
1) users interact with a QueryWebPart instance via the UI: sorting, filtering etc.
2) then I'd like to get the 'state' of the new view of the QueryWebPart instance to be passed to the R back-end: sorting state and the corresponding column ids, set of applied filters and the corresponding column ids OR may be the row ids (not idea, but ok)

Otherwise, what is the point of having a QueryWebPart?

Thanks.
-Leo
 
 
Ben Bimber responded:  2014-08-20 12:14
Hi Leo,

I've done this sort of thing before (minus R) and it is possible. I think the general approach is to work with the DataRegion, rather than the QWP itself. The QWP has a reference to the DataRegion (probably this.dataRegion, although I dont know for certain). LABKEY.DataRegion has some JS doc on available methods, but you should be able to use this to change sort, filter, etc.

There is probably a success callback on QWP, which would allow your code to act once the DataRegion loads. DataRegion also has some events for filter change, etc., which might be useful for your situation.
 
Leo Dashevskiy responded:  2014-08-20 17:35
Thanks, Ben!

Yes, I saw the DataRegion API, but it was confusing to me how to use it.
I still cannot quite figure it out. Would you have an example on how to use it along with a QueryWebPart?

Thanks.
-Leo
 
trent responded:  2014-08-22 00:33
Hi Leo,

I normally get the DataRegion with the getDataRegion function that belongs to the QWP (though isn't on the API docs).

var wp = new LABKEY.QueryWebPart({..});
var dataReg = wp.getDataRegion();

then e.g. current filters

    var filters = dataReg.getUserFilterArray();
    Ext4.each(filters,function(filter){
        var col = filter.getColumnName();
        var type = filter.getFilterType().getDisplayText();
        var val = filter.getValue();
        
        console.log('Filtering ' + col + ' with condition:' + type + ' ' + val);
        
    });

Though, playing around. This doesn't appear to return filters when the data has been filtered with view, customize view UI. And neither is sort info return with dataReg.getUserSort()

I discovered you can fetch the sort info with the qwp object: wp.userSort. Which returns a comma separated string of all the columns you are sorting by. But again, not when using the customise view UI - I'm not sure how to get that info..

Anyway, not sure if that helps any.
 
Leo Dashevskiy responded:  2014-08-27 12:12
Ok, yes, getUserFilter() and getUserFilterArray() are the 2 pieces of API that seem to return what I need.

Thanks.