Mui数据网格返回行号NaN

编程入门 行业动态 更新时间:2024-10-06 01:37:12

Mui数据网格返回<a href=https://www.elefans.com/category/jswz/34/1742939.html style=行号NaN"/>

Mui数据网格返回行号NaN

import React, { useState, useEffect } from "react";

import axios from "axios";

import io from "socket.io-client";

import { DataGrid } from "@mui/x-data-grid";

import NaveBar from "../NaveBar/NaveBar";

import SideBar from "../SideBar/SideBar";

import "./NewsTable.scss";

const socket = io("http://localhost:5000/");

const NewsTablee = () => {

  const [news, setNews] = useState([]);

  //update news deeebd

  useEffect(() => {

    const fetchData = async () => {

      try {

        const allnews = await axios.get("http://localhost:5000/api/news");

        setNews(allnews.data.Date);

      } catch (error) {

        console.log(error);

      }

    };

    socket.on("updateNewsTable", () => {

      fetchData();

    });

  }, [news]);

  useEffect(() => {

    axios

      .get("http://localhost:5000/api/news")

      .then((s) => {

        setNews(s.data.Date);

      })

      .catch((er) => {

        console.log(er);

      });

  }, []);

  const message = () => {

    socket.emit("a news updated", "a news updated");

  };

  const columns = [

    {

      field: "_id",

      headerName: "no",

      flex: 0.5,

      renderCell: (params) => {

        console.log(params.row.Index + 1); // add this line

        return <div>{(params.row.index + 1).toString()}</div>

        ;

      },

    },

    { field: "Title", headerName: "Title", flex: 3, sortable: true },

    { field: "createdAt", headerName: "createdAt", flex: 2 },

    { field: "UserName", headerName: "UserName", flex: 1 },

    { field: "Resurce", headerName: "Resurce", flex: 1 },

    { field: "Language", headerName: "Language", flex: 1 },

    { field: "ProtectionLevel", headerName: "Protection Level", flex: 1 },

    { field: "priority", headerName: "Priority", flex: 1 },

    { field: "Media", headerName: "Media", flex: 1 },

  ];

  return (

    <>

      <NaveBar />

      <SideBar />

      <div className='content-wrapper' style={{ minHeight: "1172.56px" }}>

        <div className='NewsTableContainer'>

          <div className='headrt'>

            <button

              onClick={message}

              style={{ height: 30, width: 30 }}></button>

          </div>

          <div style={{ height: "570px", width: "100%" }} className='newsTable'>

            <DataGrid

              rows={news}

              columns={columns}

              getRowId={(row) => row._id}

              sortModel={[{ field: "createdAt", sort: "desc" }]}

            />

          </div>

        </div>

      </div>

    </>

  );

};

导出默认的 NewsTablee;}

返回行号中的 nan

回答如下:

更多推荐

Mui数据网格返回行号NaN

本文发布于:2024-05-13 16:56:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1760183.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:行号   网格   数据   Mui   NaN

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!