Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[data grid] align: 'right' is not applied when using valueGetter #13268

Open
callbackKid opened this issue May 16, 2024 · 1 comment
Open

[data grid] align: 'right' is not applied when using valueGetter #13268

callbackKid opened this issue May 16, 2024 · 1 comment
Labels
component: data grid This is the name of the generic UI component, not the React module! customization: css Design CSS customizability status: waiting for author Issue with insufficient information

Comments

@callbackKid
Copy link

callbackKid commented May 16, 2024

Steps to reproduce

Hi, I've got a problem while trying to apply a align: 'right' to my cell

when I use only ValueGetter, nothing changes

{
  field: 'size',
  sortable: true,
  headerName: t('Size (MB)'),
  headerAlign: 'right',
  align: 'right',
  valueGetter: ({ value }: GridValueGetterParams<Backup, Backup['size']>) =>
    formatBytesToMB(notUndefined(value)),
}

but when I use renderCell just to render the value it works:

{
  field: 'size',
  sortable: true,
  headerName: t('Size (MB)'),
  headerAlign: 'right',
  align: 'right',
  valueGetter: ({ value }: GridValueGetterParams<Backup, Backup['size']>) =>
    formatBytesToMB(notUndefined(value)),
  renderCell: ({ value }) => <HighlightedTextSpan text={value} />,
},

so, the question is: is it a bug, or expected behavior?
if yes, why it is so? why style is not applied?

my guess is that it is possible because I use a special component to render string cells, and because I use rendercell in it it overrides the valueGetter

export const useGridStringColDef = (filterMode: GridFeatureMode) => {
  const { gridServerStringOperators, gridClientStringOperators } = useGridStringOperators();

  const getRenderCell = (value: any, row: any) => {
    if (value === null || value === undefined || value === '') {
      return <TypographyBody2>&mdash;</TypographyBody2>;
    }

    if (typeof value !== 'string') {
      throw new Error('The value must be of type "string"');
    }

    return (
      <RowExpander>
        <TypographyBody2 disabled={row.rowDisabled}>
          <HighlightedTextSpan text={value} />
        </TypographyBody2>
      </RowExpander>
    );
  };

  const gridServerStringColDef: GridColTypeDef = {
    type: 'string',
    filterOperators: gridServerStringOperators,
    renderCell: ({ formattedValue, row }) => getRenderCell(formattedValue, row),
  };

  const gridClientStringColDef: GridColTypeDef = {
    type: 'string',
    filterOperators: gridClientStringOperators,
    renderCell: ({ formattedValue, row }) => getRenderCell(formattedValue, row),
  };

  return {
    gridStringColDef: filterMode === 'server' ? gridServerStringColDef : gridClientStringColDef,
  };
};     

Current behavior

Hi, I am trying to apply a align: 'right' to my cell when I use only ValueGetter, nothing changes. But when I use renderCell just to render the value it works. so, the question is: is it a bug, or expected behavior? it yes, why it is so? why style is not applied?

Expected behavior

No response

Context

No response

Your environment

npx @mui/envinfo
  I use the latest version of the chrome 

Search keywords: valueGetter, align, renderCell,

Search keywords:

@callbackKid callbackKid added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label May 16, 2024
@ZeeshanTamboli ZeeshanTamboli transferred this issue from mui/material-ui May 27, 2024
@zannager zannager added the component: data grid This is the name of the generic UI component, not the React module! label May 27, 2024
@michelengelen michelengelen changed the title align: 'right' is not applied when using valueGetter [data grid] align: 'right' is not applied when using valueGetter May 28, 2024
@michelengelen michelengelen added customization: css Design CSS customizability bug 🐛 Something doesn't work and removed bug 🐛 Something doesn't work labels May 28, 2024
@michelengelen
Copy link
Member

I cannot reproduce this on my local instance with our demo.
Here is an example in codesandbox.

Could you please try to create a minimal reproduction example?

@michelengelen michelengelen added status: waiting for author Issue with insufficient information and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: data grid This is the name of the generic UI component, not the React module! customization: css Design CSS customizability status: waiting for author Issue with insufficient information
Projects
None yet
Development

No branches or pull requests

4 participants