Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi everyone,
I am trying to find a way of getting all selections made in a field.
With:
app.getList('CurrentSelections',function(reply){
...
})
I am able to get the qSelectionObject and from that I can get the qSelectedFieldSelectionInfo array. Unfortunately this seems to be bound by the qSelectionThreshold which is 6 for some reason. Therefore I am only able to get 6 selected values from a field, however qSelected says 32 of 350 so my question is, how do I get the other 26 selected values?
Glad for any input on this. Also Ideas on other ways to get slices of data from the internal model are welcome.
Thanks,
Marco
The filter is returning an empty array because your selected row is outside of the 200 rows returned by getData method. So, for lots of rows, probably easier to create a list. Same idea as field api, but instead of using the shorthand field api, we have much more control, we can return more rows, and sort by state, so selected values are always in our list. And since we can sort by selection state, you only need to fetch the max number of rows you think will ever be selected at one time, since they will be the first to return.
app.createList({
qDef: {
qFieldDefs: ["myfieldname"] //set fieldname
},
qAutoSortByState: {
qDisplayNumberOfRows: 1
},
qInitialDataFetch: [{
qHeight : 100, //can set number of rows returned
qWidth : 1
}]
}, function(reply) {
var rows = _.flatten(reply.qListObject.qDataPages[0].qMatrix);
var selected = rows.filter(function(row) {
return row.qState === "S";
});
console.log(selected);
});
Use the field api and filter on qState.
// Field API getData method, returns rows of field
var fieldData = app.field("myfieldname").getData();
// function to return selected rows
function getSelectedRows() {
return fieldData.rows.filter(function(row) { return row.qState === "S"; });
}
// use OnData notification to get selected rows each update
fieldData.OnData.bind(function() {
console.log(getSelectedRows());
});
// can also run getSelectedRows right away
console.log(getSelectedRows());
Hi Francis,
thank you for your fast response. This looks promising, however the array returned by the function getSelectedRows() is empty when I try to run it. This seems to be an issue with the filter. Just returning the fieldData.rows array works fine.
Anyhow, I noticed, that the array counts only 200 entries which is not even close to the size of my real applications' database. Will the other rows be dropped or is it possible to extend the scope to more than 200 rows?
Thanks for your help. Much appreciated.
The filter is returning an empty array because your selected row is outside of the 200 rows returned by getData method. So, for lots of rows, probably easier to create a list. Same idea as field api, but instead of using the shorthand field api, we have much more control, we can return more rows, and sort by state, so selected values are always in our list. And since we can sort by selection state, you only need to fetch the max number of rows you think will ever be selected at one time, since they will be the first to return.
app.createList({
qDef: {
qFieldDefs: ["myfieldname"] //set fieldname
},
qAutoSortByState: {
qDisplayNumberOfRows: 1
},
qInitialDataFetch: [{
qHeight : 100, //can set number of rows returned
qWidth : 1
}]
}, function(reply) {
var rows = _.flatten(reply.qListObject.qDataPages[0].qMatrix);
var selected = rows.filter(function(row) {
return row.qState === "S";
});
console.log(selected);
});
Awesome, this seems to Work. You helped me a lot with this.
Could you maybe briefly explain what _.flatten(reply.qListObject.qDataPages[0].qMatrix); does?
Thank you very much!
Sure...
so reply.qListObject.qDataPages[0].qMatrix is the location of the data in the reply. But if you don't flatten it, each row is returned as an array with 1 item. What _.flatten() does is it takes each array in the qMatrix array, and adds its contents to the qMatrix array. You can see the docs here Underscore.js (underscore.js is loaded with the qlik require.js file).
So we could do this fine without using _.flatten(), it just makes the code nicer to read to me. Without _.flatten(), lines 13 and 14 would look like this instead
var rows = reply.qListObject.qDataPages[0].qMatrix;
var selected = rows.filter(function(row) {
return row[0].qState === "S"; //notice i have to use row[0] now instead of just row
});