日期值未显示在银网格表中

rta7y2nd  于 2022-09-21  发布在  React
关注(0)|答案(1)|浏览(133)

我正在尝试让日期值显示在农业网格表中。日期值显示在具有名称属性的其他表中,但不会显示在没有显示在此表中的某个表中。

下面是我的代码。我尝试Map来自数据的响应,但无济于事

useEffect(() => {
      getData();
    }, []);

    const getData = () => {
      axios.get(apiUrl).then(res => {
      res?.data.map(n => n.startDate);
      setTableData(res.data);
     }).catch(error => {
     console.warn(error, 'api-error');
    });
   };

JSX

return(
      <div className="ag-theme-alpine" style={{ height: '600px' }}>
      <AgGridReact
        rowData={tableData}
        defaultColDef={defaultColDef}
        columnDefs={columnDefs}
        onGridReady={onGridReady}
        pagination={true}
        paginationPageSize={12}
        enableBrowserTooltips={true}
      ></AgGridReact>
    </div>
   )
vybvopom

vybvopom1#

请看到一个简单的柱塞与AG网格React包含下面的代码片段。在这个柱塞示例中,onGridReady事件一旦接收到数据,我就向每一行添加Date对象。并且Date对象显示在网格中。

转载:

1.开启柱塞连杆
1.刷新预览

柱塞示例:https://plnkr.co/edit/q0tT2ER9G6B6OBkK?preview

import React, { useCallback, useMemo, useRef, useState } from 'react';
import { render } from 'react-dom';
import { AgGridReact } from 'ag-grid-react';
import 'ag-grid-community/styles/ag-grid.css';
import 'ag-grid-community/styles/ag-theme-alpine.css';

const GridExample = () => {
  const containerStyle = useMemo(() => ({ width: '100%', height: '100%' }), []);

  const [rowData, setRowData] = useState();

  const [columnDefs, setColumnDefs] = useState([
    { field: 'country', maxWidth: 200 },
    { field: 'date', width: 500 },
  ]);

  const onGridReady = useCallback((params) => {
    fetch('https://www.ag-grid.com/example-assets/olympic-winners.json')
      .then((resp) => resp.json())
      .then((data) =>
        setRowData(data.map((oneRow) => ({ ...oneRow, date: new Date() })))
      );
  }, []);

  return (
    <div style={containerStyle}>
      <div style={containerStyle} className="ag-theme-alpine">
        <AgGridReact
          rowData={rowData}
          columnDefs={columnDefs}
          onGridReady={onGridReady}
        ></AgGridReact>
      </div>
    </div>
  );
};

相关问题