Skip to main content
Yianni_Ververis
Employee
Employee

In an earlier tutorial I described how to create a bootstrap drop down Mashup Editor - Create a Bootstrap Drop Down selection menu

What if you need to create more than one drop down in a single page? For this, I have create a simple reusable object that you can call as many times as you need.

Open the files from the previous tutorial and start making some changes.

  • We will remove the function showData of Line 115 and the app.createList from Line 137.

  • We need to add our data holders.

var data = {

    hq: {},

    rf: {}

};

  • Then, our function that will be getting the list data.

function getFieldData (field, callback, title) {

  app.createList({

       qDef: {

            qGrouping: "H",

            qFieldDefs: [

                 field

            ],

            qSortCriterias: [{

                 qSortByAscii: 1,

                 qSortByLoadOrder: 1

            }],

       },

       qInitialDataFetch: [{

            qTop : 0,

            qLeft : 0,

            qHeight : 1000,

            qWidth : 1

       }],

       qShowAlternatives: false,

       }, function(reply) {

            field = (title) ? title : field;

            data.hq[field] = reply.qListObject.qDataPages[0].qMatrix;

            refactorFieldData(field);

            callback(true);

       });

  };

  • Refactor Data to a more readable format rather than qText etc.

  function refactorFieldData (field) {

       var tdata = [];

       $.each(data.hq[field], function(key, value) {

            if (value[0].qState!=='X') {

                tdata.push(value[0].qText);

            }

       });

       data.rf[field] = tdata;

  };

  • Now, we need to add a function the will create the bootstrap drop down menu

function createFieldFilter (field, fieldName) {

     fieldName = (fieldName) ? fieldName : field;

     if (data.rf[field].length > 1) {

          var $element = $('#dropdown'+field + ' ul');

          $element.empty();

          $.each(data.rf[field], function(key, value) {

               $element.append('<li><a data-select="'+ field + '" data-fieldname="'+ fieldName + '" data-value="'+ value + '">'+value+'</a></li>');

          });

     }

};

  • Add the Html code. Make sure that the id starts with dropdown and have the Field name at the end

<div class="dropdown" id="dropdownYear">

     <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">

          Select Year

          <span class="caret"></span>

     </button>

     <ul class="dropdown-menu scrollable-menu" aria-labelledby="dropdownYear"></ul>

</div>

  • Lets add the code that will bind all of these into one statement

getFieldData('Year', function () {

     createFieldFilter('Year');

});

   

     This will get all of the data for the field 'Year' => add it into the object data.hq['Year'] => refactor it into a more readable format => put into data.rf['Year'] => createFieldFilter will look for the id dropdown+field and add the elements.

  • You can repeat the last javascript and html code for as many drop downs you would like to make. For this instance, I will recreate the 'Case Owner Group' from the last tutorial
  • HTML

<div class="dropdown" id="dropdownCaseOwnerGroup">

     <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">

          Select Department

          <span class="caret"></span>

     </button>

     <ul class="dropdown-menu scrollable-menu" aria-labelledby="dropdownCaseOwnerGroup"></ul>

</div>

  • JS

getFieldData('Case Owner Group', function () {

     createFieldFilter('CaseOwnerGroup', 'Case Owner Group');

}, 'CaseOwnerGroup');


You see in this one I am passing 2 parameters. This is because the field name has spaces and it will cause issues. So the first parameter is the name we will be using through out our code and the second, is the one that we will use to communicate with Sense for data retrieval and data selection.


  • Finally, let's alter the on click event that handles the selections on Line 108 to this:

$('body').on( "click", "[data-select]", function() {

     var field = $(this).data('select');

     var fieldName = $(this).data('fieldname');

     var value = $(this).data('value');

     app.field(fieldName).selectValues([value], true, false);

     $('#dropdown'+field + ' button').html(value + ' <span class="caret"></span>');

     $('#dropdown'+field + ' ul li').removeClass('active');

     $('#dropdown'+field + ' ul li:contains(\''+value+'\')').addClass('active');

});

  • If you want to use the 'ClearAll' button from the top toolbar then you will need to add in Line 72 under the case 'clearAll' :

  $('#dropdownCaseOwnerGroup button').html('Select Department <span class="caret"></span>');

  $('#dropdownYear button').html('Select Year <span class="caret"></span>');

Our webpage should like this now

preview.png

That's it. Let me know if you run into any issues. I will be more than glad to help you with this!

Yianni

8 Comments
Yianni_Ververis
Employee
Employee

You can also find it as an extension here

SenseUI-DropDown

0 Likes
1,751 Views
Anonymous
Not applicable

Hi Yianni, thanks for your great tutorial.

I create a Qlik Sense App, which has several sheets.

I need to put the sheets to different pages at Qlik mashup.

Could you please give any suggestion or example about how to create a Qlik mashup with multi-pages?

As I use a Qlik Sense extension to navigate among different sheets at Qlik Sense Desktop.

How could I still navigate among different page at Qlik mashup pages? It is better to keep the same button navigation feature at Qlik Sense Desktop.

Any suggestion or example is appreciated!

0 Likes
1,751 Views
Yianni_Ververis
Employee
Employee

Hello Haikuo,

Donwload and install my template

Qlik Branch

Examples with this tempalte:

A simple one with 3 pages

http://webapps.qlik.com/forbes/survey2016/index.html#/

A more advanced one with multiple pages, multiple sites and multiple qvfs

Qlarion Community Center

Yianni

0 Likes
1,751 Views
Anonymous
Not applicable

Hi Yianni, thanks so much for your help!

0 Likes
1,751 Views
Anonymous
Not applicable

Hi Yainni,

I have followed all the steps mentioned in the blog above and not able to see the field values in the drop down filters. I have to add a filter panel but I am trying to start with a single filter.

Here is my HTML Script for a single filter:

<div class="col-sm-4 qvplaceholder">

  <div class="dropdown" id="dropdownBrandName"> 

     <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"> 

          Select Brand 

          <span class="caret"></span> 

     </button> 

     <ul class="dropdown-menu scrollable-menu" aria-labelledby="dropdownBrandName"></ul> 

  </div>


</div >

Here is my JS Script:

//callbacks -- inserted here --

var data = { 

    hq: {}, 

    rf: {} 

}; 

function getFieldData (field, callback, title) { 

  app.createList({ 

       qDef: { 

            qGrouping: "H", 

            qFieldDefs: [ 

                 field 

            ], 

            qSortCriterias: [{ 

                 qSortByAscii: 1, 

                 qSortByLoadOrder: 1 

            }], 

       }, 

       qInitialDataFetch: [{ 

            qTop : 0, 

            qLeft : 0, 

            qHeight : 1000, 

            qWidth : 1 

       }], 

       qShowAlternatives: false, 

       }, function(reply) { 

            field = (title) ? title : field; 

            data.hq[field] = reply.qListObject.qDataPages[0].qMatrix; 

            refactorFieldData(field); 

            callback(true); 

       }); 

  }; 

 

 

  function refactorFieldData (field) { 

       var tdata = []; 

       $.each(data.hq[field], function(key, value) { 

            if (value[0].qState!=='X') { 

                tdata.push(value[0].qText); 

            } 

       }); 

       data.rf[field] = tdata; 

  };

 

function createFieldFilter (field, fieldName) { 

     fieldName = (fieldName) ? fieldName : field; 

     if (data.rf[field].length > 1) { 

          var $element = $('#dropdown'+field + ' ul'); 

          $element.empty(); 

          $.each(data.rf[field], function(key, value) { 

               $element.append('<li><a data-select="'+ field + '" data-fieldname="'+ fieldName + '" data-value="'+ value + '">'+value+'</a></li>'); 

          }); 

     } 

}; 

getFieldData('Brand Name', function () { 

     createFieldFilter('BrandName', 'Brand Name'); 

}, 'BrandName');

Kindly let me know what can I do to see the required values in the filter.

Thanks,

Mridula Gupta

0 Likes
1,751 Views
a_anhtt812
Contributor
Contributor

Hi jvs ,

I am using script tutorial have issue:

1nd choice:

2nd choice:

It trouble when I choose 2 select RB data does not exist,Please suggest my problem, Thanks

0 Likes
1,751 Views
nvrphanikumar
Creator
Creator

Hi Yianni Ververis,

thank you for the great tips here.

I have a need to show all possible values in a bootstrap menu, but upon selecting value from the menu, would like to pass that as a variable to qlik instead of applying filters to the whole app.

This way, I'm not actually filtering the whole application with value selections from bootstrap,Instead i'm passing the value to one chart that has set expressions accepting variable values from bootstrap drowdown.

Thank you

0 Likes
1,421 Views
nisarq12345
Contributor
Contributor

Hi Yainni,

Thanks for this post. I have successful created bootstrap List. However, My requirement is select multiple values at a time from the list. Currently only 2 values I'm able to select. Can you please help me how to write the code for multiple selection.

Thanks in Advance!!!

0 Likes
952 Views