Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make an entire row clickable in a DetailsList component? (office-ui-fabric)

I've been using the DetailsList component but haven't found a way to make an entire row clickable - is there a sample code snippet or pointers on how this can be achieved?

https://developer.microsoft.com/en-us/fabric#/components/detailslist

like image 246
Jorge Aguirre Avatar asked Dec 21 '25 21:12

Jorge Aguirre


2 Answers

Here is th e single click solution, Use onActiveItemChanged prop like:

const _onActiveItemChanged = (item): void => {
    alert(`Item invoked: ${JSON.stringify(item)}`);
  };

here is the DetailList

<DetailsList
      items={assessmentList}
      compact={false}
      columns={columns}
      onActiveItemChanged={_onActiveItemChanged } 
/>
like image 60
Yasir Ali Avatar answered Dec 31 '25 06:12

Yasir Ali


Overriding onRenderRow worked for me.

const _columns: IColumn[] = [
  {
    key: 'name',
    name: 'Name',
    fieldName: 'name',
    minWidth: 100,
    maxWidth: 200,
    isResizable: true
  },
  {
    key: 'value',
    name: 'Value',
    fieldName: 'value',
    minWidth: 100,
    maxWidth: 200,
    isResizable: true,
  }
];

const _items = Array.apply(null, Array(10)).map((_: any, num: number) => ({
  key: num.toString(),
  name: `Item ${num.toString()}`,
  value: num.toString()
}));

class Content extends React.Component {
  private _renderRow(props: Fabric.IDetailsRowProps, defaultRender: any): JSX.Element {
     return (
      <Fabric.DetailsRow {...props} onClick={() => alert('click')}/>
     );
   }

  public render() {
    return (
      <Fabric.Fabric>
          <Fabric.DetailsList
            items={ _items } 
            columns={ _columns.concat(..._columns, ..._columns, ..._columns) }
            onRenderRow={this._renderRow}
          />        
      </Fabric.Fabric>
    );
  }
}

ReactDOM.render( 
  <Content />,
  document.getElementById('content')
);
like image 45
Jorge Aguirre Avatar answered Dec 31 '25 06:12

Jorge Aguirre



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!