newbie
newbie

Reputation: 11

How to preview a file in a pop up window in the community page LWC Salesforce

I'm stuck to that issues and don't know how to fix that, so As I know standard library such as 'NavigationMixin' for file preview won't correctly work in the community page, so that code won't work

const docId = 'testcontdocid'
this[NavigationMixin.Navigate]({
  type: 'standard__namedPage',
  attributes: {
      pageName: 'filePreview'
  },
  state : {
      selectedRecordId: docId
  }
})

Anyway i found a solution, its to create corresponding record in 'ContentDistribution' object and DistributionPublicUrl field on contentDistribution gets populated automatically. then i can use it something like that:

this[NavigationMixin.Navigate]({
        type: 'standard__webPage',
        attributes: {
            url: DistributionPublicUrl
        }
    });

And it works perfect, but opens the file in the new browser window, not in popup window. Does anyone knows how to fix that? Thanks in advance. By the way i use lwc

Upvotes: 1

Views: 2752

Answers (4)

sumankanth kuruba
sumankanth kuruba

Reputation: 41

I had faced similar issue with community page. Instead of using NavigationMixin, please try using Lightning-Modal component.

This component helps in generating a pop up in same window.

Refer: https://developer.salesforce.com/docs/component-library/bundle/lightning-modal/documentation

Upvotes: 0

pavi
pavi

Reputation: 1

In the community it will openup in a new window for this code and i didnt find a way to pop-up in the same window as it shows in the internal salesforce org :(

`this[NavigationMixin.Navigate]({
    type: 'standard__webPage',
    attributes: {
        url: DistributionPublicUrl
    }
});`

and this below approaches we take us to the detail page of contentDocument in the new tab when we try to open in community

 `this[NavigationMixin.Navigate]({
        type: 'standard__namedPage',
        attributes: {
            pageName: 'filePreview'
        },
        state : {
            selectedRecordId: file.ContentDocumentId
        }
    })`
this[NavigationMixin.Navigate]({
        type: 'standard__namedPage',
        attributes: {
            pageName: 'filePreview'
        },
        state : {
            selectedRecordId: file.ContentDocumentId
        }
    })

Upvotes: 0

Dinesh S
Dinesh S

Reputation: 1

It's showing pop up

this[NavigationMixin.Navigate](
   {
        type: 'standard__recordPage',
        attributes: {
            recordId: recordId, // pass the record id here.
            actionName: 'edit',
        },
    });

Upvotes: 0

WendyBird
WendyBird

Reputation: 1

This worked for me and displayed the preview, in the community, in the pop-up as wished:

        this[NavigationMixin.Navigate]({
            type: 'standard__namedPage',
            attributes: {
                pageName: 'filePreview'
            },
            state : {
                selectedRecordId: file.ContentDocumentId
            }
        })

Upvotes: 0

Related Questions