ReactJS:默认情况下如何在材料表中选中以进行选择?

时间:2020-10-27 14:19:28

标签: javascript reactjs material-ui material-table

我在我的项目中使用反应物料表,并且我想默认选中选择。如何实现?

function BasicSelection() {
  return (
    <MaterialTable
      title="Basic Selection Preview"
      columns={[
        { title: 'Name', field: 'name' },
        { title: 'Surname', field: 'surname' },
        { title: 'Birth Year', field: 'birthYear', type: 'numeric' },
        {
          title: 'Birth Place',
          field: 'birthCity',
          lookup: { 34: 'İstanbul', 63: 'Şanlıurfa' },
        },
      ]}
      data={[
        { name: 'Mehmet', surname: 'Baran', birthYear: 1987, birthCity: 63 },
        { name: 'Zerya Betül', surname: 'Baran', birthYear: 2017, birthCity: 34 },
      ]}        
      options={{
        selection: true
      }}
    />
  )
}

1 个答案:

答案 0 :(得分:0)

您可以使用它。

options={{
        selection: true,
        selectionProps: rowData => ({
          disabled: rowData.name === 'Mehmet',
          color: 'primary',
          checked: rowData.id === '1'
        })
      }}