【问题标题】:how to display grouped header in muidatatable in react js如何在反应js中的muidatatable中显示分组标题
【发布时间】:2022-01-05 09:27:06
【问题描述】:

enter image description here

如上图所示,我想将其显示在带有分组标题的 muidatatable 中

我尝试了下面的代码,但我没有得到带有分组标题的正确表格,它只显示标题而不是分组标题

const columns=[
    {
      name: 'Name',
      headerCellProps: {
        style: {
          textAlign: 'center',
          border: 0,
          background: blue[500],
        },
      },
      columns: [
        {
          name: 'firstName',
          header: 'First Name',
        },
        {
          name: 'lastName',
          header: 'Last Name',
        },
      ],
    },
    {
      name: 'age',
      header: 'Age',
      headerCellProps: {
        style: {
          background: orange[500],
        },
      },
    },
    {
      name: 'Job',
      headerCellProps: {
        style: { textAlign: 'center', border: 0, background: purple[500] },
      },
      columns: [
        {
          name: 'jobTitle',
          header: 'Title',
        },
        {
          name: 'jobArea',
          header: 'Area',
        },
      ],
    },
  ]

【问题讨论】:

    标签: reactjs material-ui mui-datatable


    【解决方案1】:
     const columns = [
         
            
            {
                name: 'Health & Safety',
                // label:'Manual Handling',
                options: {
                    filter: true,
                    customHeadRender: (tableMeta,value) => 
                    (<>
                       <th className={classes.thhead} >
                          <th className={classes.thsubhead} >
                          <span className={classes.headSpan} >Health & Safety</span>
                        {EMP.filter( item => item.TrainingCategory === 'Health & Safety').map((EMPLOYE)=>{
                          
                                return(
                                   <th style={{border:"0px",paddingLeft:"0px",paddingTop:"0px",paddingBottom:"0px"}} >
                                 {/* <span className={classes.headSpan} >Health & Safety</span> */}
                                 <th className={classes.headvalueOne}  >
                                 {EMPLOYE.TrainingName}
                                 </th>
                               </th>
                                )
                              })
                           }
                        </th>
                  </th>
                             
                        
                    </>),
                    customBodyRender: (value) => (
                      <td className={classes.tdHead}>
                          <td className={classes.tdsubHead} >
                          { EMP? 
                                EMP.map((EMPLOYE)=>{
                                return(
                                  <td className={classes.TablevalueOne} >{EMPLOYE.JobTitileNumber}</td>
                                )
                              }):null}
                        </td>
                    </td>
                  ),
                }
            },
         
     },
    
        ];
    

    【讨论】:

      猜你喜欢
      • 2023-01-16
      • 2019-06-10
      • 2020-09-14
      • 1970-01-01
      • 1970-01-01
      • 2021-11-22
      • 1970-01-01
      • 2021-08-01
      • 1970-01-01
      相关资源
      最近更新 更多