How to refresh Fabric-Ui DetailsList when updating a row





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I'm trying to create a fabric-ui detailsList component. This component should simply represents what i have in my database with the possibility to update a specific column value for each row. To do the updating, each row should have a fabric-ui PrimaryButton.
I also created two APIs in my server (GET and POST). The GET request will returns to the react app all the resources that will be shown and the POST (called whne clicking on the PrimaryButton of a specific row) will have in parameter the Id of the row and will update the value of the column.



I created a root component:App which load DetailsList and call GET API to get all the resources and show them. I also created a child component:ResolveButton which will be called for each row in the details list in the root component.



App.tsx:



import * as React from 'react';
import ResolveButton from './ResolveButton';


export interface IDetailsListCustomColumnsExampleState {
sortedItems?: any;
columns?: IColumn;
hasError: boolean;
}


export class App extends React.Component<{}, IDetailsListCustomColumnsExampleState> {
public constructor(props: {}) {
super(props);

this.state = {
columns: ,
hasError:false,
sortedItems:
};
this._renderItemColumn=this._renderItemColumn.bind(this);
this.changeStatus = this.changeStatus.bind(this);
}
public componentDidCatch() {
// Display fallback UI
this.setState({ hasError: true });
}
public componentDidMount(){
this.fetchResult()
}
public render() {
const { sortedItems, columns } = this.state;
if (this.state.hasError) {
// You can render any custom fallback UI
return <h1>Something went wrong.</h1>;
}
else{
return (
<DetailsList
items={sortedItems as any}
setKey="set"
columns={columns}
onRenderItemColumn={this._renderItemColumn}
onColumnHeaderClick={this.onColumnClick}
onItemInvoked={this._onItemInvoked}
onColumnHeaderContextMenu={this._onColumnHeaderContextMenu}
ariaLabelForSelectionColumn="Toggle selection"
ariaLabelForSelectAllCheckbox="Toggle selection for all items"
/>
);
}

}
public changeStatus (itemId:React.ReactText){
// TODO : call the POST API to update the status
const { sortedItems } = this.state;
const resolvedKey='Status';
const idKey='Id';

sortedItems!.map(ite => {
if(ite[idKey] === itemId){
ite[resolvedKey] = 3;
}
return ite;
})
this.setState({
sortedItems
});
}
private fetchResult = () =>{
fetch('https://localhost:44329/home')
.then((response) => response.json())
.then(json => this.setState({ columns: _buildColumns(json),
sortedItems: json })).catch((error) =>
{
this.componentDidCatch()
})
}

private onColumnClick = (event: React.MouseEvent<HTMLElement>, column: IColumn): void => {
const { columns } = this.state;
let { sortedItems } = this.state;
let isSortedDescending = column.isSortedDescending;

// If we've sorted this column, flip it.
if (column.isSorted) {
isSortedDescending = !isSortedDescending;
}

// Sort the items.
sortedItems = sortedItems!.concat().sort((a, b) => {
const firstValue = a[column.fieldName || ''];
const secondValue = b[column.fieldName || ''];

if (isSortedDescending) {
return firstValue > secondValue ? -1 : 1;
} else {
return firstValue > secondValue ? 1 : -1;
}
});

// Reset the items and columns to match the state.
this.setState({
columns: columns!.map(col => {
col.isSorted = col.key === column.key;

if (col.isSorted) {
col.isSortedDescending = isSortedDescending;
}

return col;
}),
sortedItems
});
};

private _onColumnHeaderContextMenu(column: IColumn | undefined, ev: React.MouseEvent<HTMLElement> | undefined): void {

alert(`column ${column!.key} contextmenu opened.`);
}

private _onItemInvoked(item: any, index: number | undefined): void {
alert(`Item ${item.name} at index ${index} has been invoked.`);
}

private _renderItemColumn(item: any, index: number, column: IColumn) {

const fieldContent = item[column.fieldName || ''];

const crisisColor = {
1: 'Red',
2: 'Orange',
3: 'Yellow',
4: 'Green'
}
const crisis = {
1: 'Crise',
2: 'Haute',
3: 'Moyenne',
4: 'Basse'
}
const statusColor = {
1: 'Black',
2: 'Black',
3: 'Green'
}
const status = {
1: 'Ouvert',
2: 'En cours',
3: 'Résolu'
}
const resolvedKey='Status';
const isResolved = item[resolvedKey]===3;
switch (column.key) {
case 'Status':
return (
<span data-selection-disabled={true} style={{ color: statusColor[fieldContent], height: '100%', display: 'block' }}>
{status[fieldContent]}
</span>
);

case 'Criticity':
return (
<span data-selection-disabled={true} style={{ color: crisisColor[fieldContent], height: '100%', display: 'block' }}>
{crisis[fieldContent]}
</span>
);
case 'Creator':
return(
<div>
<img src="https://img.mobiscroll.com/demos/BMW_logo.png" width="30px" height="30px" style={{verticalAlign: 'middle', display:'inline' }}/>
<p style={{verticalAlign: 'middle', display:'inline' , paddingLeft:'10px'}}>{fieldContent}</p>
</div>
);
case 'AssignedTo':
return(
<div>
<img src="https://img.mobiscroll.com/demos/BMW_logo.png" width="30px" height="30px" style={{verticalAlign: 'middle', display:'inline' }}/>
<p style={{verticalAlign: 'middle', display:'inline' , paddingLeft:'10px'}}>{fieldContent}</p>
</div>
);

case 'Id':
return(
// tslint:disable-next-line jsx-no-lambda
<ResolveButton disabled={isResolved} uniqueId={fieldContent} changeStatus={ ()=>this.changeStatus(fieldContent)} />
);

default:
return <span>{fieldContent}</span>;
}
}
}
function _buildColumns(json:any) {
const columns = buildColumns(json);
return columns;
}

export default App;


ResolveButton.tsx



import { PrimaryButton } from 'office-ui-fabric-react/lib/Button';
import * as React from 'react';

export interface IHandleChange {
changeStatus: ()=>void;
disabled:boolean;
uniqueId:string| number;
}
export class ResolveButton extends React.Component<IHandleChange, {}> {
constructor(props:any) {

super(props);
}
public render(): JSX.Element {
return (
<div>
{
!this.props.disabled &&
<PrimaryButton
data-automation-id="test"
text="Résolu"
onClick={this.props.changeStatus}
allowDisabledFocus={true}
/>
}
</div>
);
}
}
export default ResolveButton;


As you can see in my App.tsx i create the ResolveButton component when the column key is "Id".
My problem is that when clicking on the button the data will be updated in the database but what is shown in the react app is always the old version of the database, so i need to refresh the page when calling the POST API.










share|improve this question































    0















    I'm trying to create a fabric-ui detailsList component. This component should simply represents what i have in my database with the possibility to update a specific column value for each row. To do the updating, each row should have a fabric-ui PrimaryButton.
    I also created two APIs in my server (GET and POST). The GET request will returns to the react app all the resources that will be shown and the POST (called whne clicking on the PrimaryButton of a specific row) will have in parameter the Id of the row and will update the value of the column.



    I created a root component:App which load DetailsList and call GET API to get all the resources and show them. I also created a child component:ResolveButton which will be called for each row in the details list in the root component.



    App.tsx:



    import * as React from 'react';
    import ResolveButton from './ResolveButton';


    export interface IDetailsListCustomColumnsExampleState {
    sortedItems?: any;
    columns?: IColumn;
    hasError: boolean;
    }


    export class App extends React.Component<{}, IDetailsListCustomColumnsExampleState> {
    public constructor(props: {}) {
    super(props);

    this.state = {
    columns: ,
    hasError:false,
    sortedItems:
    };
    this._renderItemColumn=this._renderItemColumn.bind(this);
    this.changeStatus = this.changeStatus.bind(this);
    }
    public componentDidCatch() {
    // Display fallback UI
    this.setState({ hasError: true });
    }
    public componentDidMount(){
    this.fetchResult()
    }
    public render() {
    const { sortedItems, columns } = this.state;
    if (this.state.hasError) {
    // You can render any custom fallback UI
    return <h1>Something went wrong.</h1>;
    }
    else{
    return (
    <DetailsList
    items={sortedItems as any}
    setKey="set"
    columns={columns}
    onRenderItemColumn={this._renderItemColumn}
    onColumnHeaderClick={this.onColumnClick}
    onItemInvoked={this._onItemInvoked}
    onColumnHeaderContextMenu={this._onColumnHeaderContextMenu}
    ariaLabelForSelectionColumn="Toggle selection"
    ariaLabelForSelectAllCheckbox="Toggle selection for all items"
    />
    );
    }

    }
    public changeStatus (itemId:React.ReactText){
    // TODO : call the POST API to update the status
    const { sortedItems } = this.state;
    const resolvedKey='Status';
    const idKey='Id';

    sortedItems!.map(ite => {
    if(ite[idKey] === itemId){
    ite[resolvedKey] = 3;
    }
    return ite;
    })
    this.setState({
    sortedItems
    });
    }
    private fetchResult = () =>{
    fetch('https://localhost:44329/home')
    .then((response) => response.json())
    .then(json => this.setState({ columns: _buildColumns(json),
    sortedItems: json })).catch((error) =>
    {
    this.componentDidCatch()
    })
    }

    private onColumnClick = (event: React.MouseEvent<HTMLElement>, column: IColumn): void => {
    const { columns } = this.state;
    let { sortedItems } = this.state;
    let isSortedDescending = column.isSortedDescending;

    // If we've sorted this column, flip it.
    if (column.isSorted) {
    isSortedDescending = !isSortedDescending;
    }

    // Sort the items.
    sortedItems = sortedItems!.concat().sort((a, b) => {
    const firstValue = a[column.fieldName || ''];
    const secondValue = b[column.fieldName || ''];

    if (isSortedDescending) {
    return firstValue > secondValue ? -1 : 1;
    } else {
    return firstValue > secondValue ? 1 : -1;
    }
    });

    // Reset the items and columns to match the state.
    this.setState({
    columns: columns!.map(col => {
    col.isSorted = col.key === column.key;

    if (col.isSorted) {
    col.isSortedDescending = isSortedDescending;
    }

    return col;
    }),
    sortedItems
    });
    };

    private _onColumnHeaderContextMenu(column: IColumn | undefined, ev: React.MouseEvent<HTMLElement> | undefined): void {

    alert(`column ${column!.key} contextmenu opened.`);
    }

    private _onItemInvoked(item: any, index: number | undefined): void {
    alert(`Item ${item.name} at index ${index} has been invoked.`);
    }

    private _renderItemColumn(item: any, index: number, column: IColumn) {

    const fieldContent = item[column.fieldName || ''];

    const crisisColor = {
    1: 'Red',
    2: 'Orange',
    3: 'Yellow',
    4: 'Green'
    }
    const crisis = {
    1: 'Crise',
    2: 'Haute',
    3: 'Moyenne',
    4: 'Basse'
    }
    const statusColor = {
    1: 'Black',
    2: 'Black',
    3: 'Green'
    }
    const status = {
    1: 'Ouvert',
    2: 'En cours',
    3: 'Résolu'
    }
    const resolvedKey='Status';
    const isResolved = item[resolvedKey]===3;
    switch (column.key) {
    case 'Status':
    return (
    <span data-selection-disabled={true} style={{ color: statusColor[fieldContent], height: '100%', display: 'block' }}>
    {status[fieldContent]}
    </span>
    );

    case 'Criticity':
    return (
    <span data-selection-disabled={true} style={{ color: crisisColor[fieldContent], height: '100%', display: 'block' }}>
    {crisis[fieldContent]}
    </span>
    );
    case 'Creator':
    return(
    <div>
    <img src="https://img.mobiscroll.com/demos/BMW_logo.png" width="30px" height="30px" style={{verticalAlign: 'middle', display:'inline' }}/>
    <p style={{verticalAlign: 'middle', display:'inline' , paddingLeft:'10px'}}>{fieldContent}</p>
    </div>
    );
    case 'AssignedTo':
    return(
    <div>
    <img src="https://img.mobiscroll.com/demos/BMW_logo.png" width="30px" height="30px" style={{verticalAlign: 'middle', display:'inline' }}/>
    <p style={{verticalAlign: 'middle', display:'inline' , paddingLeft:'10px'}}>{fieldContent}</p>
    </div>
    );

    case 'Id':
    return(
    // tslint:disable-next-line jsx-no-lambda
    <ResolveButton disabled={isResolved} uniqueId={fieldContent} changeStatus={ ()=>this.changeStatus(fieldContent)} />
    );

    default:
    return <span>{fieldContent}</span>;
    }
    }
    }
    function _buildColumns(json:any) {
    const columns = buildColumns(json);
    return columns;
    }

    export default App;


    ResolveButton.tsx



    import { PrimaryButton } from 'office-ui-fabric-react/lib/Button';
    import * as React from 'react';

    export interface IHandleChange {
    changeStatus: ()=>void;
    disabled:boolean;
    uniqueId:string| number;
    }
    export class ResolveButton extends React.Component<IHandleChange, {}> {
    constructor(props:any) {

    super(props);
    }
    public render(): JSX.Element {
    return (
    <div>
    {
    !this.props.disabled &&
    <PrimaryButton
    data-automation-id="test"
    text="Résolu"
    onClick={this.props.changeStatus}
    allowDisabledFocus={true}
    />
    }
    </div>
    );
    }
    }
    export default ResolveButton;


    As you can see in my App.tsx i create the ResolveButton component when the column key is "Id".
    My problem is that when clicking on the button the data will be updated in the database but what is shown in the react app is always the old version of the database, so i need to refresh the page when calling the POST API.










    share|improve this question



























      0












      0








      0








      I'm trying to create a fabric-ui detailsList component. This component should simply represents what i have in my database with the possibility to update a specific column value for each row. To do the updating, each row should have a fabric-ui PrimaryButton.
      I also created two APIs in my server (GET and POST). The GET request will returns to the react app all the resources that will be shown and the POST (called whne clicking on the PrimaryButton of a specific row) will have in parameter the Id of the row and will update the value of the column.



      I created a root component:App which load DetailsList and call GET API to get all the resources and show them. I also created a child component:ResolveButton which will be called for each row in the details list in the root component.



      App.tsx:



      import * as React from 'react';
      import ResolveButton from './ResolveButton';


      export interface IDetailsListCustomColumnsExampleState {
      sortedItems?: any;
      columns?: IColumn;
      hasError: boolean;
      }


      export class App extends React.Component<{}, IDetailsListCustomColumnsExampleState> {
      public constructor(props: {}) {
      super(props);

      this.state = {
      columns: ,
      hasError:false,
      sortedItems:
      };
      this._renderItemColumn=this._renderItemColumn.bind(this);
      this.changeStatus = this.changeStatus.bind(this);
      }
      public componentDidCatch() {
      // Display fallback UI
      this.setState({ hasError: true });
      }
      public componentDidMount(){
      this.fetchResult()
      }
      public render() {
      const { sortedItems, columns } = this.state;
      if (this.state.hasError) {
      // You can render any custom fallback UI
      return <h1>Something went wrong.</h1>;
      }
      else{
      return (
      <DetailsList
      items={sortedItems as any}
      setKey="set"
      columns={columns}
      onRenderItemColumn={this._renderItemColumn}
      onColumnHeaderClick={this.onColumnClick}
      onItemInvoked={this._onItemInvoked}
      onColumnHeaderContextMenu={this._onColumnHeaderContextMenu}
      ariaLabelForSelectionColumn="Toggle selection"
      ariaLabelForSelectAllCheckbox="Toggle selection for all items"
      />
      );
      }

      }
      public changeStatus (itemId:React.ReactText){
      // TODO : call the POST API to update the status
      const { sortedItems } = this.state;
      const resolvedKey='Status';
      const idKey='Id';

      sortedItems!.map(ite => {
      if(ite[idKey] === itemId){
      ite[resolvedKey] = 3;
      }
      return ite;
      })
      this.setState({
      sortedItems
      });
      }
      private fetchResult = () =>{
      fetch('https://localhost:44329/home')
      .then((response) => response.json())
      .then(json => this.setState({ columns: _buildColumns(json),
      sortedItems: json })).catch((error) =>
      {
      this.componentDidCatch()
      })
      }

      private onColumnClick = (event: React.MouseEvent<HTMLElement>, column: IColumn): void => {
      const { columns } = this.state;
      let { sortedItems } = this.state;
      let isSortedDescending = column.isSortedDescending;

      // If we've sorted this column, flip it.
      if (column.isSorted) {
      isSortedDescending = !isSortedDescending;
      }

      // Sort the items.
      sortedItems = sortedItems!.concat().sort((a, b) => {
      const firstValue = a[column.fieldName || ''];
      const secondValue = b[column.fieldName || ''];

      if (isSortedDescending) {
      return firstValue > secondValue ? -1 : 1;
      } else {
      return firstValue > secondValue ? 1 : -1;
      }
      });

      // Reset the items and columns to match the state.
      this.setState({
      columns: columns!.map(col => {
      col.isSorted = col.key === column.key;

      if (col.isSorted) {
      col.isSortedDescending = isSortedDescending;
      }

      return col;
      }),
      sortedItems
      });
      };

      private _onColumnHeaderContextMenu(column: IColumn | undefined, ev: React.MouseEvent<HTMLElement> | undefined): void {

      alert(`column ${column!.key} contextmenu opened.`);
      }

      private _onItemInvoked(item: any, index: number | undefined): void {
      alert(`Item ${item.name} at index ${index} has been invoked.`);
      }

      private _renderItemColumn(item: any, index: number, column: IColumn) {

      const fieldContent = item[column.fieldName || ''];

      const crisisColor = {
      1: 'Red',
      2: 'Orange',
      3: 'Yellow',
      4: 'Green'
      }
      const crisis = {
      1: 'Crise',
      2: 'Haute',
      3: 'Moyenne',
      4: 'Basse'
      }
      const statusColor = {
      1: 'Black',
      2: 'Black',
      3: 'Green'
      }
      const status = {
      1: 'Ouvert',
      2: 'En cours',
      3: 'Résolu'
      }
      const resolvedKey='Status';
      const isResolved = item[resolvedKey]===3;
      switch (column.key) {
      case 'Status':
      return (
      <span data-selection-disabled={true} style={{ color: statusColor[fieldContent], height: '100%', display: 'block' }}>
      {status[fieldContent]}
      </span>
      );

      case 'Criticity':
      return (
      <span data-selection-disabled={true} style={{ color: crisisColor[fieldContent], height: '100%', display: 'block' }}>
      {crisis[fieldContent]}
      </span>
      );
      case 'Creator':
      return(
      <div>
      <img src="https://img.mobiscroll.com/demos/BMW_logo.png" width="30px" height="30px" style={{verticalAlign: 'middle', display:'inline' }}/>
      <p style={{verticalAlign: 'middle', display:'inline' , paddingLeft:'10px'}}>{fieldContent}</p>
      </div>
      );
      case 'AssignedTo':
      return(
      <div>
      <img src="https://img.mobiscroll.com/demos/BMW_logo.png" width="30px" height="30px" style={{verticalAlign: 'middle', display:'inline' }}/>
      <p style={{verticalAlign: 'middle', display:'inline' , paddingLeft:'10px'}}>{fieldContent}</p>
      </div>
      );

      case 'Id':
      return(
      // tslint:disable-next-line jsx-no-lambda
      <ResolveButton disabled={isResolved} uniqueId={fieldContent} changeStatus={ ()=>this.changeStatus(fieldContent)} />
      );

      default:
      return <span>{fieldContent}</span>;
      }
      }
      }
      function _buildColumns(json:any) {
      const columns = buildColumns(json);
      return columns;
      }

      export default App;


      ResolveButton.tsx



      import { PrimaryButton } from 'office-ui-fabric-react/lib/Button';
      import * as React from 'react';

      export interface IHandleChange {
      changeStatus: ()=>void;
      disabled:boolean;
      uniqueId:string| number;
      }
      export class ResolveButton extends React.Component<IHandleChange, {}> {
      constructor(props:any) {

      super(props);
      }
      public render(): JSX.Element {
      return (
      <div>
      {
      !this.props.disabled &&
      <PrimaryButton
      data-automation-id="test"
      text="Résolu"
      onClick={this.props.changeStatus}
      allowDisabledFocus={true}
      />
      }
      </div>
      );
      }
      }
      export default ResolveButton;


      As you can see in my App.tsx i create the ResolveButton component when the column key is "Id".
      My problem is that when clicking on the button the data will be updated in the database but what is shown in the react app is always the old version of the database, so i need to refresh the page when calling the POST API.










      share|improve this question
















      I'm trying to create a fabric-ui detailsList component. This component should simply represents what i have in my database with the possibility to update a specific column value for each row. To do the updating, each row should have a fabric-ui PrimaryButton.
      I also created two APIs in my server (GET and POST). The GET request will returns to the react app all the resources that will be shown and the POST (called whne clicking on the PrimaryButton of a specific row) will have in parameter the Id of the row and will update the value of the column.



      I created a root component:App which load DetailsList and call GET API to get all the resources and show them. I also created a child component:ResolveButton which will be called for each row in the details list in the root component.



      App.tsx:



      import * as React from 'react';
      import ResolveButton from './ResolveButton';


      export interface IDetailsListCustomColumnsExampleState {
      sortedItems?: any;
      columns?: IColumn;
      hasError: boolean;
      }


      export class App extends React.Component<{}, IDetailsListCustomColumnsExampleState> {
      public constructor(props: {}) {
      super(props);

      this.state = {
      columns: ,
      hasError:false,
      sortedItems:
      };
      this._renderItemColumn=this._renderItemColumn.bind(this);
      this.changeStatus = this.changeStatus.bind(this);
      }
      public componentDidCatch() {
      // Display fallback UI
      this.setState({ hasError: true });
      }
      public componentDidMount(){
      this.fetchResult()
      }
      public render() {
      const { sortedItems, columns } = this.state;
      if (this.state.hasError) {
      // You can render any custom fallback UI
      return <h1>Something went wrong.</h1>;
      }
      else{
      return (
      <DetailsList
      items={sortedItems as any}
      setKey="set"
      columns={columns}
      onRenderItemColumn={this._renderItemColumn}
      onColumnHeaderClick={this.onColumnClick}
      onItemInvoked={this._onItemInvoked}
      onColumnHeaderContextMenu={this._onColumnHeaderContextMenu}
      ariaLabelForSelectionColumn="Toggle selection"
      ariaLabelForSelectAllCheckbox="Toggle selection for all items"
      />
      );
      }

      }
      public changeStatus (itemId:React.ReactText){
      // TODO : call the POST API to update the status
      const { sortedItems } = this.state;
      const resolvedKey='Status';
      const idKey='Id';

      sortedItems!.map(ite => {
      if(ite[idKey] === itemId){
      ite[resolvedKey] = 3;
      }
      return ite;
      })
      this.setState({
      sortedItems
      });
      }
      private fetchResult = () =>{
      fetch('https://localhost:44329/home')
      .then((response) => response.json())
      .then(json => this.setState({ columns: _buildColumns(json),
      sortedItems: json })).catch((error) =>
      {
      this.componentDidCatch()
      })
      }

      private onColumnClick = (event: React.MouseEvent<HTMLElement>, column: IColumn): void => {
      const { columns } = this.state;
      let { sortedItems } = this.state;
      let isSortedDescending = column.isSortedDescending;

      // If we've sorted this column, flip it.
      if (column.isSorted) {
      isSortedDescending = !isSortedDescending;
      }

      // Sort the items.
      sortedItems = sortedItems!.concat().sort((a, b) => {
      const firstValue = a[column.fieldName || ''];
      const secondValue = b[column.fieldName || ''];

      if (isSortedDescending) {
      return firstValue > secondValue ? -1 : 1;
      } else {
      return firstValue > secondValue ? 1 : -1;
      }
      });

      // Reset the items and columns to match the state.
      this.setState({
      columns: columns!.map(col => {
      col.isSorted = col.key === column.key;

      if (col.isSorted) {
      col.isSortedDescending = isSortedDescending;
      }

      return col;
      }),
      sortedItems
      });
      };

      private _onColumnHeaderContextMenu(column: IColumn | undefined, ev: React.MouseEvent<HTMLElement> | undefined): void {

      alert(`column ${column!.key} contextmenu opened.`);
      }

      private _onItemInvoked(item: any, index: number | undefined): void {
      alert(`Item ${item.name} at index ${index} has been invoked.`);
      }

      private _renderItemColumn(item: any, index: number, column: IColumn) {

      const fieldContent = item[column.fieldName || ''];

      const crisisColor = {
      1: 'Red',
      2: 'Orange',
      3: 'Yellow',
      4: 'Green'
      }
      const crisis = {
      1: 'Crise',
      2: 'Haute',
      3: 'Moyenne',
      4: 'Basse'
      }
      const statusColor = {
      1: 'Black',
      2: 'Black',
      3: 'Green'
      }
      const status = {
      1: 'Ouvert',
      2: 'En cours',
      3: 'Résolu'
      }
      const resolvedKey='Status';
      const isResolved = item[resolvedKey]===3;
      switch (column.key) {
      case 'Status':
      return (
      <span data-selection-disabled={true} style={{ color: statusColor[fieldContent], height: '100%', display: 'block' }}>
      {status[fieldContent]}
      </span>
      );

      case 'Criticity':
      return (
      <span data-selection-disabled={true} style={{ color: crisisColor[fieldContent], height: '100%', display: 'block' }}>
      {crisis[fieldContent]}
      </span>
      );
      case 'Creator':
      return(
      <div>
      <img src="https://img.mobiscroll.com/demos/BMW_logo.png" width="30px" height="30px" style={{verticalAlign: 'middle', display:'inline' }}/>
      <p style={{verticalAlign: 'middle', display:'inline' , paddingLeft:'10px'}}>{fieldContent}</p>
      </div>
      );
      case 'AssignedTo':
      return(
      <div>
      <img src="https://img.mobiscroll.com/demos/BMW_logo.png" width="30px" height="30px" style={{verticalAlign: 'middle', display:'inline' }}/>
      <p style={{verticalAlign: 'middle', display:'inline' , paddingLeft:'10px'}}>{fieldContent}</p>
      </div>
      );

      case 'Id':
      return(
      // tslint:disable-next-line jsx-no-lambda
      <ResolveButton disabled={isResolved} uniqueId={fieldContent} changeStatus={ ()=>this.changeStatus(fieldContent)} />
      );

      default:
      return <span>{fieldContent}</span>;
      }
      }
      }
      function _buildColumns(json:any) {
      const columns = buildColumns(json);
      return columns;
      }

      export default App;


      ResolveButton.tsx



      import { PrimaryButton } from 'office-ui-fabric-react/lib/Button';
      import * as React from 'react';

      export interface IHandleChange {
      changeStatus: ()=>void;
      disabled:boolean;
      uniqueId:string| number;
      }
      export class ResolveButton extends React.Component<IHandleChange, {}> {
      constructor(props:any) {

      super(props);
      }
      public render(): JSX.Element {
      return (
      <div>
      {
      !this.props.disabled &&
      <PrimaryButton
      data-automation-id="test"
      text="Résolu"
      onClick={this.props.changeStatus}
      allowDisabledFocus={true}
      />
      }
      </div>
      );
      }
      }
      export default ResolveButton;


      As you can see in my App.tsx i create the ResolveButton component when the column key is "Id".
      My problem is that when clicking on the button the data will be updated in the database but what is shown in the react app is always the old version of the database, so i need to refresh the page when calling the POST API.







      reactjs components office-ui-fabric






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 7 at 8:31







      Soufien Hajji

















      asked Jan 4 at 9:15









      Soufien HajjiSoufien Hajji

      114112




      114112
























          1 Answer
          1






          active

          oldest

          votes


















          2














          This is a react type question.



          Your DetailList uses sortedItems to manage its state. Therefore, when you click on ResolveButton you need to update the sate. Which is not happening



          To fix this, ResolveButton should expose a property called onResolved so the main component could handle to update its state.



          class ResolveButton extends React.Component<IButtonProps, {}> {
          async handleClick() {
          const response = await fetch('https://localhost:44329/home')
          const json = await response.json();

          if (this.props.onResolved) {
          this.props.onResolved(json);
          }
          }
          }


          .



          In the App just call the onResolved to update the state



          class App extends React.Component<{}, IDetailsListCustomColumnsExampleState> {

          <ResolveButton
          disabled={isResolved}
          uniqueId={fieldContent}
          onResolved={(data) => setState({'sortedItems': data})
          />

          }





          share|improve this answer
























          • Thanks. I happend to do something like that using "SetState" function. But i don't know if it's the right choice to use it if i want to bind the data shown with the data in the database. What i have done so far is that if the use click on the button the function "changeStatus" will be executed. This function will update the data in both the state of my component and my database. I updated my question with my new code, can you please take a look at the "changeStatus" function and tell me if what i'm doing is right ?

            – Soufien Hajji
            Jan 7 at 8:34











          • @SoufienHajji onClick is a function onClick={() => this.props.changeStatus(this.props.uniqueId)}

            – Mohamed Mansour
            Jan 13 at 9:51














          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54035964%2fhow-to-refresh-fabric-ui-detailslist-when-updating-a-row%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          This is a react type question.



          Your DetailList uses sortedItems to manage its state. Therefore, when you click on ResolveButton you need to update the sate. Which is not happening



          To fix this, ResolveButton should expose a property called onResolved so the main component could handle to update its state.



          class ResolveButton extends React.Component<IButtonProps, {}> {
          async handleClick() {
          const response = await fetch('https://localhost:44329/home')
          const json = await response.json();

          if (this.props.onResolved) {
          this.props.onResolved(json);
          }
          }
          }


          .



          In the App just call the onResolved to update the state



          class App extends React.Component<{}, IDetailsListCustomColumnsExampleState> {

          <ResolveButton
          disabled={isResolved}
          uniqueId={fieldContent}
          onResolved={(data) => setState({'sortedItems': data})
          />

          }





          share|improve this answer
























          • Thanks. I happend to do something like that using "SetState" function. But i don't know if it's the right choice to use it if i want to bind the data shown with the data in the database. What i have done so far is that if the use click on the button the function "changeStatus" will be executed. This function will update the data in both the state of my component and my database. I updated my question with my new code, can you please take a look at the "changeStatus" function and tell me if what i'm doing is right ?

            – Soufien Hajji
            Jan 7 at 8:34











          • @SoufienHajji onClick is a function onClick={() => this.props.changeStatus(this.props.uniqueId)}

            – Mohamed Mansour
            Jan 13 at 9:51


















          2














          This is a react type question.



          Your DetailList uses sortedItems to manage its state. Therefore, when you click on ResolveButton you need to update the sate. Which is not happening



          To fix this, ResolveButton should expose a property called onResolved so the main component could handle to update its state.



          class ResolveButton extends React.Component<IButtonProps, {}> {
          async handleClick() {
          const response = await fetch('https://localhost:44329/home')
          const json = await response.json();

          if (this.props.onResolved) {
          this.props.onResolved(json);
          }
          }
          }


          .



          In the App just call the onResolved to update the state



          class App extends React.Component<{}, IDetailsListCustomColumnsExampleState> {

          <ResolveButton
          disabled={isResolved}
          uniqueId={fieldContent}
          onResolved={(data) => setState({'sortedItems': data})
          />

          }





          share|improve this answer
























          • Thanks. I happend to do something like that using "SetState" function. But i don't know if it's the right choice to use it if i want to bind the data shown with the data in the database. What i have done so far is that if the use click on the button the function "changeStatus" will be executed. This function will update the data in both the state of my component and my database. I updated my question with my new code, can you please take a look at the "changeStatus" function and tell me if what i'm doing is right ?

            – Soufien Hajji
            Jan 7 at 8:34











          • @SoufienHajji onClick is a function onClick={() => this.props.changeStatus(this.props.uniqueId)}

            – Mohamed Mansour
            Jan 13 at 9:51
















          2












          2








          2







          This is a react type question.



          Your DetailList uses sortedItems to manage its state. Therefore, when you click on ResolveButton you need to update the sate. Which is not happening



          To fix this, ResolveButton should expose a property called onResolved so the main component could handle to update its state.



          class ResolveButton extends React.Component<IButtonProps, {}> {
          async handleClick() {
          const response = await fetch('https://localhost:44329/home')
          const json = await response.json();

          if (this.props.onResolved) {
          this.props.onResolved(json);
          }
          }
          }


          .



          In the App just call the onResolved to update the state



          class App extends React.Component<{}, IDetailsListCustomColumnsExampleState> {

          <ResolveButton
          disabled={isResolved}
          uniqueId={fieldContent}
          onResolved={(data) => setState({'sortedItems': data})
          />

          }





          share|improve this answer













          This is a react type question.



          Your DetailList uses sortedItems to manage its state. Therefore, when you click on ResolveButton you need to update the sate. Which is not happening



          To fix this, ResolveButton should expose a property called onResolved so the main component could handle to update its state.



          class ResolveButton extends React.Component<IButtonProps, {}> {
          async handleClick() {
          const response = await fetch('https://localhost:44329/home')
          const json = await response.json();

          if (this.props.onResolved) {
          this.props.onResolved(json);
          }
          }
          }


          .



          In the App just call the onResolved to update the state



          class App extends React.Component<{}, IDetailsListCustomColumnsExampleState> {

          <ResolveButton
          disabled={isResolved}
          uniqueId={fieldContent}
          onResolved={(data) => setState({'sortedItems': data})
          />

          }






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 4 at 23:17









          Mohamed MansourMohamed Mansour

          31.7k610083




          31.7k610083













          • Thanks. I happend to do something like that using "SetState" function. But i don't know if it's the right choice to use it if i want to bind the data shown with the data in the database. What i have done so far is that if the use click on the button the function "changeStatus" will be executed. This function will update the data in both the state of my component and my database. I updated my question with my new code, can you please take a look at the "changeStatus" function and tell me if what i'm doing is right ?

            – Soufien Hajji
            Jan 7 at 8:34











          • @SoufienHajji onClick is a function onClick={() => this.props.changeStatus(this.props.uniqueId)}

            – Mohamed Mansour
            Jan 13 at 9:51





















          • Thanks. I happend to do something like that using "SetState" function. But i don't know if it's the right choice to use it if i want to bind the data shown with the data in the database. What i have done so far is that if the use click on the button the function "changeStatus" will be executed. This function will update the data in both the state of my component and my database. I updated my question with my new code, can you please take a look at the "changeStatus" function and tell me if what i'm doing is right ?

            – Soufien Hajji
            Jan 7 at 8:34











          • @SoufienHajji onClick is a function onClick={() => this.props.changeStatus(this.props.uniqueId)}

            – Mohamed Mansour
            Jan 13 at 9:51



















          Thanks. I happend to do something like that using "SetState" function. But i don't know if it's the right choice to use it if i want to bind the data shown with the data in the database. What i have done so far is that if the use click on the button the function "changeStatus" will be executed. This function will update the data in both the state of my component and my database. I updated my question with my new code, can you please take a look at the "changeStatus" function and tell me if what i'm doing is right ?

          – Soufien Hajji
          Jan 7 at 8:34





          Thanks. I happend to do something like that using "SetState" function. But i don't know if it's the right choice to use it if i want to bind the data shown with the data in the database. What i have done so far is that if the use click on the button the function "changeStatus" will be executed. This function will update the data in both the state of my component and my database. I updated my question with my new code, can you please take a look at the "changeStatus" function and tell me if what i'm doing is right ?

          – Soufien Hajji
          Jan 7 at 8:34













          @SoufienHajji onClick is a function onClick={() => this.props.changeStatus(this.props.uniqueId)}

          – Mohamed Mansour
          Jan 13 at 9:51







          @SoufienHajji onClick is a function onClick={() => this.props.changeStatus(this.props.uniqueId)}

          – Mohamed Mansour
          Jan 13 at 9:51






















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54035964%2fhow-to-refresh-fabric-ui-detailslist-when-updating-a-row%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Monofisismo

          Angular Downloading a file using contenturl with Basic Authentication

          Olmecas