1 Reply Latest reply: Jul 13, 2016 9:29 AM by Jérémy George RSS

    Doubt in qlikview extension

    vivek Moningi

      Hi guys,

       

      i have a JS script file in Qlikview , i have written a code:

      var td = _this.Data;
        for(var rowIx = 0; rowIx < td.Rows.length; rowIx++) {
        //set the current row to a variable
           var row = td.Rows[rowIx];
           var start=row[0].text;
            var end= row[1].text
      ;document.getElementById(start).addEventListener(some function);
      document.getElementById(start).addEventListener(some function);
      }
      

      the problem is the getElementByID is not retrieving any value , what i need is the value or ID need to be passed .

      Kindly please suggest me any alternative for this

      Thank,

      Vivek

        • Re: Doubt in qlikview extension
          Jérémy George

          The document.getElementById function retrieves a DOM element with a given id. The content of the Data.Rows is not DOM elements but plain javascript object without representation in the document.

          You have first to create a DOM element containing your extension data, add it to your extension element (which is this.Element in your function), and then add an event listener to it.

           

          For example:

           

          var td = _this.Data;  
          for(var rowIx = 0; rowIx < td.Rows.length; rowIx++) {
            var row = td.Rows[rowIx];  
            var start = row[0].text;  
            var end = row[1].text;
            // create a <div> element representing the data row
            var start_element = document.createElement('div');
            // set the content of the <div> to be the text of the first column of the row
            start_element.innerHTML = start;
            // add the div to the extension element
            _this.Element.appendChild(start_element);
            // listen to the 'click' event on the element
            start_element.addEventListener('click', function() { alert('I was clicked!');  });
          }
          

           

          Note that you don't have to call document.getElementById since you already have a reference to the element (returned by createElement).