簡體   English   中英

Reactjs:加載物料表時如何使所有行checkbox都為true?

[英]Reactjs: How to make all row checkbox check true when material table is loaded?

我在我的項目中使用反應材料表,我想默認選中選擇。 如何實現?

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: 'a', surname: 'b', birthYear: c, birthCity: d },
        { name: 'e', surname: 'f', birthYear: g, birthCity: h },
      ]}        
      options={{
        selection: true
      }}
    />
  )
}

您可以在選擇道具中指定選中狀態。

options={{
    selection: true,
    selectionProps: rowData => ({
      checked: true,
    })
 }}

在這里,它始終檢查行。 您可以更新 function 以具有基於選擇更改事件的條件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM