Render a DetailsList component with all items preselected

时间:2019-05-31 11:34:24

标签: office-ui-fabric

I want to render a DetailsList with all items in that list preselected. I pass a Selection prop to the DetailsList, but calling setAllSelected() on the Selection from the component's constructor won't render all items as selected.

  • Though, calling setAllSelected() from an event handler would select all items as expected.
  • I have tried to call setAllSelected() from componentDidMount(), but without success.
  • I suppose items must be internally created (wrt the DetailsList component) before the Selection can select them, but I have no idea how to force this.

I have added a CodePen.

1 个答案:

答案 0 :(得分:1)

您需要像这样首先设置选择项:

this._selection.setItems(this.state.items, false)

我调整了您的代码笔here进行演示。希望这会有所帮助。