0 Replies Latest reply on Jul 24, 2015 12:52 PM by Matthew Palmer

    How to automaticaly populate a filter menu using the JavaScript API?

    Matthew Palmer

      I have been trying to automatically populate a set of menus with all of the filter options available on a worksheet. This is the code that I have so far.

       

      var filtername, filterIndex, filterValue = [], filterValIndex;

      function populateMenus() {

          var onSuccess = function (filters) {

              for(i = 0; i < filters.length; i++) {

                  filterIndex = i;

                  filtername = filters[i].getFieldName();

                  populateList();

              }

      }

      }

       

      function populateList() {

          console.log(filterIndex);

          var onSuccess = function (filters) {

              var outputText;

              $.each(filters[filterIndex].getAppliedValues(), function (filter, i) {

                      // use .value property of each DataValue object

                      var str = i.value;

                      filterValue.push(str);

                      outputText = outputText + "Applied Values: " + filterValue.join(", ");

                      alert(outputText);

                      fillList();

      });

      }

      }

       

      function fillList() {

          for(j = 0; j < filterValue.length; j++) {

              $('#environment').append('<li><a href="#">' + filterValue[j] + '</a></li>');

          }

      }

       

      It does not work. I am not really sure how to get it to work. I want a separate menu for each filter populated with all filter value options.