Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set checked on item in DetailsList control

Tags:

I use DetailsList component from office-ui-fabric-react library:

   import {DetailsList} from 'office-ui-fabric-react/lib/DetailsList';
   render () {
      const item = [
        {value: 'one'},
        {value: 'two'}
      ]
      return (
        <DetailsList
            checkboxVisibility={CheckboxVisibility.always}
            items={items}
            selection={selection}
        />
    }

How to set checked for item with value `two?

like image 759
Vladimir Avatar asked Apr 07 '17 14:04

Vladimir


1 Answers

Noticed you passed a selection to DetailsList. There's a few methods in selection to do that, including:

  • setAllSelected(isAllSelected: boolean)
  • setKeySelected(key: string, isSelected: boolean, shouldAnchor: boolean)
  • setIndexSelected(index: number, isSelected: boolean, shouldAnchor: boolean)

In your case, you can give each value a key. And then call setKeySelected somewhere (for example, componentDidMount) to tell DetailsList to select specific items.

like image 137
warmsea Avatar answered Sep 24 '22 10:09

warmsea