1

I have a react app that uses package mui-datatables. I want to be redirected to "/edit-form" onRowClick, but it didn't work (nothing happens, no errors either).

import React, { Component } from "react";
import { Link as RouterLink } from "react-router-dom";
import Link from "@material-ui/core/Link";
import MUIDataTable from "mui-datatables";

class DataTable extends Component {
  state={...}
  redirectToForm = props => <RouterLink to="/edit-form" {...props}/>

  render() {
  const options = {
    onRowClick: rowData => this.redirectToForm(rowData)
  };
  
  return (
    <Link
      color="secondary"
      className={classes.button}
      component={this.goToDetailedTable}
    >
      Detail 
    </Link>
    <MUIDataTable
      title={title}
      columns={value.state.columnName}
      data={value.state.rowData}
      options={options}
    />
    )
  }

When I console.log(rowData), it did print out the row data:

const options = {
    onRowClick: rowData => console.log(rowData)
  };
akl
  • 77
  • 3
  • 9

1 Answers1

4

Instead of using <Link/> try calling history from the history package and then just history.push('edit/form').

AlanP
  • 328
  • 1
  • 5