mui / mui-x

MUI X: Build complex and data-rich applications using a growing list of advanced React components, like the Data Grid, Date and Time Pickers, Charts, and more!
https://mui.com/x/
3.92k stars 1.2k forks source link

[data grid] Base UI support, hook API #1016

Open oliviertassinari opened 3 years ago

oliviertassinari commented 3 years ago

Summary 💡

Provide a hook-only version of the data grid, a.k.a. "headless" version.

This is not to be confused with "unstyled" which is about replacing slots with your own components #10143.

Examples 🌈

import { useDataGrid, pluginA, pluginB } from '@mui/x-data-grid';

function MyApp() {
  const {
    getTableProps,
    getTableBodyProps,
    headers,
    rows,
  } = useDataGrid({ columns, rows }, pluginA, pluginB);

  return (
    <table {...getTableProps()}>
      <thead>
        {headers.map(header => (
          <tr {...header.getHeaderGroupProps()}>
            {header.columns.map(column => (
              <th {...column.getHeaderProps()}>
                {column.render('Header')}
              </th>
            ))}
          </tr>
        ))}
      </thead>
      <tbody {...getTableBodyProps()}>
        {rows.map(row => (
          <tr {...row.getRowProps()}>
            {row.cells.map(cell => (
              <td {...cell.getCellProps()}>
               {cell.render('Cell')}
              </td>
            ))}
          </tr>
        ))}
      </tbody>
    </table>
  )
}

We might need more than one hook.

Motivation 🔦

The objective is to offer a different tradeoff to the current fully featured component. We already do it with the combo box and pagination components, so we might as well do it more. I'm not entirely convinced yet that such an effort would be worth the cost. However, I think that it could be healthy from an architectural point of view.

Pros:

Cons:

This issue #924 is related to the effort. The solution of one will help the other.

Benchmark

Side note

It could make sense to make all the Pro plan available under this headless API as MIT. It's too early to say if this can work, but if after deeper research, we realize that most of the buy decision is about the pain to style, then it could fly.

joserodolfofreitas commented 1 year ago

Quoting a request from a user interview

Similar to react-table, I would like to use the Data Grid as a headless table library. Right now we are using data grids also for simple tables where we don't need cell logic, if possible, I would like to use a lighter version of the Data Grid, one that is focused only on row logic.