1 Reply Latest reply: May 26, 2017 2:26 AM by Kranti Deshpande RSS

    Need help to display sorted sheet name in drop-down list

    Kranti Deshpande

      Hi,

       

      QlikSense - I am facing issues while displaying sheet name in drop-down list in proper order. Below is the code which shows the sheet name but in random order and not in ascending or descending order. Can anyone help, doing this please? FYI, I have got this code from existing custom extension.

      ----------------------------------------------------------------

      app.getAppObjectList("sheet",function(reply)

                  {

                  console.log(reply);

                      var str = "";

                      $.each(reply.qAppObjectList.qItems, function(key, value)

                      {

                      str += value.qData.title + ' ';

                      if(currUrl.search("analysis") >-1)

                      {

                        html += '<option value="' + urlPath + value.qInfo.qId + '/state/analysis">' + value.qData.title + '</option>';

                      }

                      else

                      {

                        html += '<option>' + value.qData.title + '</option>';

                      }

                  cnt+=1;

                    });

                  html+= "</select></fieldset></form></div>";

                    $element.html( html );

                   

                    $(function(){

                      $('.dropdown').click(function(){

                        $('#sheetList').change(function(){

                          var value = $(this).val();

                          window.location.href = value;                 

                        })

                      })

                    })

      --------------------------------------------------------

      Thanks,

      Kranti

        • Re: Need help to display sorted sheet name in drop-down list
          Kranti Deshpande

          I could able to complete this task. See if it can be useful for others.

           

          app.getList("sheet",function(reply)

                      {

           

            $.each(reply.qAppObjectList.qItems, function(key, value)

                          {

            temp.push({v:value, k: key});

                        });

           

            temp.sort(function(a,b){

            if(a.v.qData.description > b.v.qData.description){ return 1}

            if(a.v.qData.description < b.v.qData.description){ return -1}

            return 0;

            });

            

            temp.sort(function(a,b){

            if(a.v.qData.title > b.v.qData.title){ return 1}

            if(a.v.qData.title < b.v.qData.title){ return -1}

            return 0;

            });

           

           

           

            $.each(temp, function(key, obj) {

            currentCat = obj.v.qData.description;

            if(currentCat != prevCat){

            prevCat = obj.v.qData.description;

            html +='<optgroup label="'+obj.v.qData.description+'">';

            }

           

            if(currUrl.search("analysis") >-1)

            {             

            html += '<option value="' + urlPath + obj.v.qInfo.qId + '/state/analysis">' + obj.v.qData.title + '</option>';

            }

            else

            {             

            html += '<option>' + obj.v.qData.title + '</option>';

            }

           

            if(currentCat != prevCat){

            html +='</optgroup>';

            }

            });