0

I have made 2 tabs , in the second tab I have a datatable in which one column holds the anchor element... In the anchor element I have "href" attribute in which I have called another function... So, whenever I switch to second tab page automatically redirects to another page without the click of the icon...

Please find the code below: This is the anchor element I am using...

<td><a href=${(this.open(JSON.parse(item.RelatedItems)[0].ItemId))}><i data-toggle="tooltip" title="Approve / Reject" class="fa fa-check-square-o fa-2x" aria-hidden="true"></i></a></td>

This is the function I have called in anchor tag:

protected open(rid){
var url : string;
let web = new Web(this.context.pageContext.web.absoluteUrl);
 web.lists.getByTitle("Test").items.select("UID,ID")
.filter("ID eq'" + rid"'").get()
.then((response)=>{
           url = this.context.pageContext.web.absoluteUrl +"/SitePages/Test.aspx?RID="+response[0].UID+"&tsk=apr&isEditable=0"
            window.location.replace(url);
        })
   }

Please suggest the workaround for the same.

0

That is because you are executing window.location.replace you just need to return the URL after creating it. The then callback should be.

.then((response)=>{
          var url = this.context.pageContext.web.absoluteUrl +"/SitePages/Test.aspx?RID="+response[0].UID+"&tsk=apr&isEditable=0"
            return url;
        })
   }

OR

As a alternative, you can create a button control and execute the function over onClick()

| improve this answer | |
  • It is not working as well.... I have tried this now but it is giving me an error that "this.open" is not function onclick =javascript:this.open(${a[0].ItemId}) – Nidhi Maheshwari Sep 4 at 4:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.