Connecting to fields

Fields are the lists of available columns in the loaded data model within the app. While Qlik Sense is mostly focused around displaying or calculating data, interacting with the Qlik Data Model is equally as important, especially if you wish to pass selections to update the calculated dataset on your Qlik objects within your mashup or web app.

To connect to fields, all you need to do is use the Field API as part of the capabilities API, which goes by the namespace qlik.app.field. You can also use enigma.js.

Connecting to fields is reasonably straightforward once you have established a connection with the Qlik Engine, since you would only extend the qlik.app, which is shown in other examples provided in this chapter.

To make things a little more interesting, we'll create a compelling code example where we'll create two buttons, which will make a selection in a field, and clear selections, respectively:

<html> 
<head>
<link href="https://<qlik_sense_servername>/resources/autogenerated/qlik-styles.css" rel="stylesheet">
<script src="https://<qlik_sense_servername>/resources/assets/external/requirejs/require.js"></script>
<script>
var config = {
host: 'localhost',
prefix: '/',
port: 443,
isSecure: true
};
require.config( {
baseUrl: ( config.isSecure? "https://" : "http://" ) + config.host + (config.port? ":" + config.port: "") + config.prefix + "resources"
});

require(["js/qlik"], function ( qlik ){
qlik.setOnError(function(error) {
alert(error.message);
});

var appName = 'Mastering QS.qvf';
if (!app){
//Get App
app = qlik.openApp(appName, config);

function makeSelection() {
var field = app.field('Case Owner Group');
field.selectAll(false)
}

function clearSelection() {
var field = app.field('Case Owner Group');
field.clear();
}

}
});
</script>
</head>
<body>
<button onclick="makeSelection()">Make Selection</button>
<button onclick="clearSelection()">Clear Selection</button>
</body>
</html>

Interacting with the Qlik data model and passing selections is a magnificent way to explore your data, which is why being familiar with connecting to fields is relevant for building compelling dashboards and adding value to the business user.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.117.148.177