I am trying to display sharepoint lookup value on DetailsList of Office UI Fabric in SPFx React webparts project but I am not able to do it. Can anyone help me acheive this? Thank you.
item value format is shown below
[
{
Id : 0,
Title : "test0",
Body : {
Body_p1: "test0_p1",
Body_p2: "test0_p2"
},
},
{
Id : 1,
Title : "test1",
Body : {
Body_p1: "test1_p1",
Body_p2: "test1_p2"
}
}
]
and I want to use this control. https://developer.microsoft.com/en-us/fabric#/controls/web/detailslist
I want to display above data like this.
|Id | Title | Body
|0 | test0 | test0_p1
|1 | test1 | test1_p1
or
|Id | Title | Body
|0 | test0 | test0_p2
|1 | test1 | test1_p2
This is SPFx webparts react project for sharepoint online.
I tired blow code but Body.Body_p1 and Body.Body_p2 values are not shwon.
Note. Item values are in {items} and I fllowed this instruction. https://developer.microsoft.com/en-us/fabric#/controls/web/detailslist/basic
export interface IListItem{
Id: number;
Title: string;
Body : {
Body_p1: string;
Body_p2: string;
};
}
export interface IReactExState{
items: IListItem[];
}
export default class ReactEx extends React.Component<IReactExProps, IReactExState>{
//some code here
private _columns: IColumn[];
if(/*conditions*/){
this._columns = [
{ key: 'Id', name: 'Id', fieldName: 'Id', minWidth: 100, maxWidth: 200, isResizable: true },
{ key: 'Title', name: 'Title', fieldName: 'Title', minWidth: 200, maxWidth: 400, isResizable: true },
{ key: 'Body', name: 'Body', fieldName: 'Body.Body_p1', minWidth: 200, maxWidth: 400, isResizable: true },
];
}
else{
this._columns = [
{ key: 'Id', name: 'Id', fieldName: 'Id', minWidth: 100, maxWidth: 200, isResizable: true },
{ key: 'Title', name: 'Title', fieldName: 'Title', minWidth: 200, maxWidth: 400, isResizable: true },
{ key: 'Body', name: 'Body', fieldName: 'Body.Body_p2', minWidth: 200, maxWidth: 400, isResizable: true },
];
}
public render(): React.ReactElement<IReactExProps>{
return(
{/*some code here*/}
<MarqueeSelection selection={this._selection}>
<DetailsList
items={items}
columns={this._colmns}
setKey="RequestID"
layoutMode={DetailsListLayoutMode.justified}
selection={this._selection}
selectionPreservedOnEmptyClick={true}
ariaLabelForSelectionColumn="Toggle selection"
ariaLabelForSelectAllCheckbox="Toggle selection for all items"
checkButtonAriaLabel="Row checkbox"
onItemInvoked={this._onItemInvoked}
/>
</MarqueeSelection>
{/*somec ode here*/}
);
}
