0

我有一个MUIDataTable,当用户单击一行时,我需要转到一个新屏幕。我只想允许一个点击的行。这是我尝试过的:

const options = {
  selectableRows: true,
  selectableRowsOnClick: true,
  onRowClick: useHistory('/app/proposals')
};

我也尝试过使用useHistory,但看起来没有触发点击。

表定义很简单:

<MUIDataTable
   data={data.hits}
   columns={columns}
   options={options}
/>

为了澄清,我不需要选择行。我想立即转到另一个页面。

4

2 回答 2

0

尝试使用文档中定义的 useHistory()

let history = useHistory();

const options = {
  selectableRows: true,
  selectableRowsOnClick: true,
  onRowClick: history.push('/app/proposals')
};
于 2020-03-03T14:55:55.493 回答
0

这就是我实现它的方式:

const options = {     
    selectableRows: "single", // no multiple rows selection for me  
    selectableRowsOnClick: true,     
    onRowsSelect: function(currentRowsSelected: array, allRowsSelected: array) {      
         let selectedIndex = currentRowsSelected[0].index;         
         setLocalStorage("whatever data I need, based on the selected row"); 
         props.history.push("my_page");    
    },
};

然后在表定义中:

options={options}
于 2020-03-04T07:43:50.843 回答