Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

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

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

1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

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>';

  }

  });

View solution in original post

1 Reply
Anonymous
Not applicable
Author

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>';

  }

  });