Merge pull request #1818 from chandaniprajapati/react-datatable-profilepic
react-datatable: Added feature to show profile picture of user column
This commit is contained in:
commit
2eff0055bb
|
@ -43,6 +43,7 @@ Version|Date|Comments
|
|||
1.1|February 24, 2021|Added support for large lists
|
||||
1.2|March 01, 2021|Fixed search issue for number field
|
||||
1.3|March 31,2021| Changed UI as per SharePoint list, Set themeing as per current SharePoint site theme, Created custom pagination by using reusable controls, Added features to export CSV based on the filter if the filter is available, Added hyperlink feature for image and link column in export to pdf and also set alternative row formatting in generated pdf as per property pane configuration odd/even row color, fixed object issue (for people/hyperlink, etc) in export to CSV.
|
||||
1.4|April 10, 2021|Added feature to show profile picture in user column and shows display name of user field in export to CSV and PDF.
|
||||
|
||||
|
||||
## Disclaimer
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 61 KiB After Width: | Height: | Size: 48 KiB |
|
@ -9,7 +9,7 @@
|
|||
"This web part provides easy way to render SharePoint custom list in data table view with all the necessary features."
|
||||
],
|
||||
"created": "2021-03-01",
|
||||
"modified": "2021-03-01",
|
||||
"modified": "2021-04-10",
|
||||
"products": [
|
||||
"SharePoint",
|
||||
"Office"
|
||||
|
|
|
@ -6,6 +6,8 @@ export function csvCellFormatter(value: any, type: string) {
|
|||
case 'SP.FieldUrl':
|
||||
value = value.props.children;
|
||||
break;
|
||||
case 'SP.FieldUser':
|
||||
value = value.props.displayName;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -7,6 +7,8 @@ export function pdfCellFormatter(value: any, type: string) {
|
|||
let { children: text, href: link } = value.props;
|
||||
value = { text, link, color: 'blue' };
|
||||
break;
|
||||
case 'SP.FieldUser':
|
||||
value = value.props.displayName;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
import * as React from 'react';
|
||||
import { Persona, PersonaSize } from 'office-ui-fabric-react/lib/Persona';
|
||||
|
||||
interface IProfilePicProps {
|
||||
loginName: string;
|
||||
displayName: string;
|
||||
getUserProfileUrl: () => Promise<string>;
|
||||
}
|
||||
|
||||
export function RenderProfilePicture(props: IProfilePicProps) {
|
||||
|
||||
const [profileUrl, setProfileUrl] = React.useState<string>();
|
||||
let { displayName, getUserProfileUrl } = props;
|
||||
|
||||
React.useEffect(() => {
|
||||
getUserProfileUrl().then(url => {
|
||||
setProfileUrl(url);
|
||||
});
|
||||
}, [props])
|
||||
|
||||
return (
|
||||
<Persona
|
||||
imageUrl={profileUrl}
|
||||
text={displayName}
|
||||
size={PersonaSize.size32}
|
||||
imageAlt={displayName}
|
||||
styles={{ primaryText: { fontSize: '12px' } }}
|
||||
/>);
|
||||
}
|
|
@ -17,7 +17,7 @@ export class SPService {
|
|||
for (var i = 0; i < selectedFields.length; i++) {
|
||||
switch (selectedFields[i].fieldType) {
|
||||
case 'SP.FieldUser':
|
||||
selectQuery.push(`${selectedFields[i].key}/Title,${selectedFields[i].key}/Name`);
|
||||
selectQuery.push(`${selectedFields[i].key}/Title,${selectedFields[i].key}/EMail,${selectedFields[i].key}/Name`);
|
||||
expandQuery.push(selectedFields[i].key);
|
||||
break;
|
||||
case 'SP.FieldLookup':
|
||||
|
@ -63,9 +63,10 @@ export class SPService {
|
|||
}
|
||||
}
|
||||
|
||||
public async getUserProfileUrl(loginName: string, propertyName: string) {
|
||||
public async getUserProfileUrl(loginName: string) {
|
||||
try {
|
||||
const profileUrl = await sp.profiles.getUserProfilePropertyFor(loginName, propertyName);
|
||||
const properties = await sp.profiles.getPropertiesFor(loginName);
|
||||
const profileUrl = properties['PictureUrl'];
|
||||
return profileUrl;
|
||||
}
|
||||
catch (err) {
|
||||
|
|
|
@ -17,7 +17,7 @@ import { DetailsList, DetailsListLayoutMode, DetailsRow, IDetailsRowStyles, IDet
|
|||
import { pdfCellFormatter } from '../../../shared/common/ExportListItemsToPDF/ExportListItemsToPDFFormatter';
|
||||
import { csvCellFormatter } from '../../../shared/common/ExportListItemsToCSV/ExportListItemsToCSVFormatter';
|
||||
import { IPropertyPaneDropdownOption } from '@microsoft/sp-property-pane';
|
||||
|
||||
import { RenderProfilePicture } from '../../../shared/common/RenderProfilePicture/RenderProfilePicture';
|
||||
|
||||
export default class ReactDatatable extends React.Component<IReactDatatableProps, IReactDatatableState> {
|
||||
|
||||
|
@ -45,6 +45,10 @@ export default class ReactDatatable extends React.Component<IReactDatatableProps
|
|||
this.getSelectedListItems();
|
||||
}
|
||||
|
||||
private getUserProfileUrl = (loginName: string) => {
|
||||
return this._services.getUserProfileUrl(loginName)
|
||||
}
|
||||
|
||||
public componentDidUpdate(prevProps: IReactDatatableProps) {
|
||||
if (prevProps.list !== this.props.list) {
|
||||
this.props.onChangeProperty("list");
|
||||
|
@ -102,7 +106,9 @@ export default class ReactDatatable extends React.Component<IReactDatatableProps
|
|||
value = value['Title'];
|
||||
break;
|
||||
case 'SP.FieldUser':
|
||||
value = value['Title'];
|
||||
let loginName = value['Name'];
|
||||
let userName = value['Title'];
|
||||
value = <RenderProfilePicture loginName={loginName} displayName={userName} getUserProfileUrl={() => this.getUserProfileUrl(loginName)} ></RenderProfilePicture>;
|
||||
break;
|
||||
case 'SP.FieldMultiLineText':
|
||||
value = <div dangerouslySetInnerHTML={{ __html: value }}></div>;
|
||||
|
@ -124,6 +130,7 @@ export default class ReactDatatable extends React.Component<IReactDatatableProps
|
|||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public formatValueForExportingData(value: any, type?: string) {
|
||||
if (!value) {
|
||||
return value;
|
||||
|
@ -153,8 +160,8 @@ export default class ReactDatatable extends React.Component<IReactDatatableProps
|
|||
}));
|
||||
}
|
||||
|
||||
private handlePaginationChange(pageNo: number, pageSize: number) {
|
||||
this.setState({ page: pageNo, rowsPerPage: pageSize });
|
||||
private handlePaginationChange(pageNo: number, rowsPerPage: number) {
|
||||
this.setState({ page: pageNo, rowsPerPage: rowsPerPage });
|
||||
}
|
||||
|
||||
public handleSearch(event: React.ChangeEvent<HTMLInputElement>) {
|
||||
|
|
Loading…
Reference in New Issue