【问题标题】:ReactJS: How to make selection by default checked in Material Table by default?ReactJS:如何在默认情况下在材料表中进行选择?
【发布时间】:2020-10-27 14:19:28
【问题描述】:

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

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
      }}
    />
  )
}

【问题讨论】:

    标签: javascript reactjs material-ui material-table


    【解决方案1】:

    你可以使用它。

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

    【讨论】:

    • 这很糟糕。问题是什么 ? selectionProps: rowData => ({ disabled: rowData.name === 'Mehmet', color: 'primary', 检查: rowData.id === 1 })
    • 我想在加载表格时选中所有行复选框
    • 你可以将代码“checked: rowData.id === '1'”修改为“checked: true”,所有行都会被检查为true
    • 我做了,但现在它是真的,无法取消选择
    猜你喜欢
    • 2019-02-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-30
    • 1970-01-01
    • 2020-03-25
    • 1970-01-01
    • 1970-01-01
    • 2018-02-01
    相关资源
    最近更新 更多