Skip to content

Instantly share code, notes, and snippets.

@mindspank
Created March 21, 2015 17:13
Show Gist options
  • Save mindspank/8ad72f953741c3ef848b to your computer and use it in GitHub Desktop.
Save mindspank/8ad72f953741c3ef848b to your computer and use it in GitHub Desktop.
Create a listbox with qsocks, sorted by expression and including a expression
/*
* Create a listobject, sort by a expression and include a expression.
* Tested on QIX Engine API 1.1
* Alexander Karlsson - http://github.com/mindspank - [email protected]
*/
//Your server you want to connect to.
var config = {
host: 'sense-demo.qlik.com',
isSecure: true
}
qsocks.Connect(config).then(function(global) {
//Open document Sales Discovery
global.openDoc('9a2471a4-3fab-48bb-9b39-d55e47ca2471').then(function(app) {
//Define our listbox definition.
//Optional parameters has been omitted
//Refer to documentation for a full list of properties
//https://help.qlik.com/sense/en-us/developer/Subsystems/EngineAPI/Content/GenericObject/PropertyLevel/ListObjectDef.htm
var obj = {
"qInfo": {
"qId": "LB01",
"qType": "ListObject"
},
"qListObjectDef": {
"qDef": {
"qFieldDefs": [
"Month"
],
"qFieldLabels": [
"Month"
],
"qSortCriterias": [{
"qSortByExpression": -1,
"qExpression": {
"qv": "=sum([Sales Amount])"
}
}]
},
"qInitialDataFetch": [{
"qTop": 0,
"qLeft": 0,
"qHeight": 100,
"qWidth": 2
}],
"qExpressions": [{
"qExpr": "=sum([Sales Amount])"
}]
}
};
//Create the listbox as a session object which will persist over the sesion and then be deleted.
app.createSessionObject(obj).then(function(list) {
//List has been created and handle returned.
//Get the layout of the listobject.
list.getLayout().then(function(layout) {
//Layout, model and data is retured.
console.log(layout)
})
})
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment