0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

めも

Posted at

import * as React from 'react';
import { DataGrid, GridColDef, GridRowsProp, getTreeDataPath } from '@mui/x-data-grid';
import styled from 'styled-components';

// カスタムスタイル
const CustomRow = styled.divborder: ${({ isGrouped, isExpanded }) => { if (isGrouped && isExpanded) { return '1px solid yellow'; } else if (isGrouped) { return '1px solid lightgray'; } else { return 'none'; } }};;

// サンプルデータ
const treeData: GridRowsProp = [
{ id: 1, name: '20世紀フォックス', level: 0 },
{ id: 2, name: 'ジェームズ・キャメロン', parentId: 1, level: 1 },
{ id: 3, name: 'アバター', parentId: 2, level: 2 },
{ id: 4, name: 'タイタニック', parentId: 2, level: 2 },
{ id: 5, name: 'サム・メンデス', parentId: 1, level: 1 },
// ...
];

const columns: GridColDef[] = [
{ field: 'name', headerName: 'タイトル', flex: 1 },
];

export default function CustomDataGrid() {
return (
<DataGrid
rows={treeData}
columns={columns}
treeData
getTreeDataPath={getTreeDataPath}
getRowHeight={() => 25} // 行の高さを調整
renderRow={(params) => {
const { row } = params;
const isGrouped = row.level > 0;
const isExpanded = // 展開状態を取得するロジック (params.api.getRowExpanded?)
return (

{params.renderCell()}

);
}}
/>
);
}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?