Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
86 views
in Technique[技术] by (71.8m points)

javascript - isDialogOpen is not set to true

I use mui-datatable for creating table in my project

I use a datatable for creating table in my project and i try to use a customDialog for confirm deleting items from the table.

When I use setIsDialogOpen(true) in handleRowsDelete callback function to change the state and showing confirmDialog, it doesn't work and isDialogOpen state doesn't become true what is the problem?

import React from "react";
import MUIDataTable from "mui-datatables";
import { Edit } from "@material-ui/icons";
import { connect } from "http2";
import ConfirmDialog from "../../partials/ConfirmDialog";

interface Data {
  name: string;
  mobile: string;
  email: string;
  createdAt: string;
  coursesCount: number;
}
interface ListProps {
  rows: Data[];
  deleteItems:Function;
}

const handleCellClick = (e: any) => {
  console.log(e);
};

export default function List({ rows , deleteItems }: ListProps) {
  const [isDialogOpen, setIsDialogOpen] = React.useState<boolean>(false)
  const [confirmDelete, setConfirmDelete] = React.useState<boolean>(false)

  const handleRowsDelete = (e: any,data:any):void|false => {
    console.log(isDialogOpen)
    setIsDialogOpen(true)
    console.log(isDialogOpen)
    return false;
  };

  const handleDialog = (isConfirm:boolean) => {
      setConfirmDelete(isConfirm)
      // setIsDialogOpen(false)
  }

  return (
    <div style={{ maxWidth: "100%" }}>
      <ConfirmDialog dialogTitle='?????' dialogBody='' isOpen={isDialogOpen} handleConfirm={handleDialog}/>
      <MUIDataTable
        title={"?????? ??"}
        data={rows}
        columns={[
          { label: "???", name: "name" },
          { label: "??????", name: "mobile" },
          { label: "?????", name: "email" },
          { label: "????? ?????", name: "createdAt" },
          { label: "????? ???? ??", name: "coursesCount" },
        ]}
        options={{
          onRowClick: handleCellClick,
          onRowsDelete: handleRowsDelete,
          textLabels: {
            body: {
              noMatch: "???????? ????? ???? ???",
              toolTip: "Sort",
              columnHeaderTooltip: (column) => `???? ???? ???? ${column.label}`,
            },
            pagination: {
              next: "???? ? ????",
              previous: "???? ? ????",
              rowsPerPage: "????? ???? ??",
              displayRows: "??",
            },
            toolbar: {
              search: "?????",
              downloadCsv: "?????? CSV",
              print: "???",
              viewColumns: "???? ??",
              filterTable: "????? ??",
            },
            filter: {
              all: "???",
              title: "????? ??",
              reset: "????????",
            },
            viewColumns: {
              title: "????? ???? ??",
              titleAria: "?????/????",
            },
            selectedRows: {
              text: "???? ?????? ??",
              delete: "???",
              deleteAria: "??? ???",
            },
          },
          rowsPerPageOptions: [10, 25, 50],
        }}
      />
    </div>
  );
}
question from:https://stackoverflow.com/questions/65938502/isdialogopen-is-not-set-to-true

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...