【问题标题】:react-admin: how to customise the bulk actionsreact-admin:如何自定义批量操作
【发布时间】:2021-02-18 22:41:41
【问题描述】:

我想禁用一些由自定义 BulkActionsButton 创建的复选框。 这是一个简单的列表:

function CourseList(props): ReactElement {
  return (
    <List
      {...props}
      bulkActionButtons={<BulkActionButton />}
    >
      <Datagrid>
         ...some fields
      </Datagrid>
    </List>
  );
}

还有BulkActionButton:

const BulkActionButton = ({
  resource,
  selectedIds,
}: BulkActionProps): ReactElement | null => {
  const { data, loading } = useGetMany(
    'shared/courses',
    selectedIds as Identifier[]
  );

  if (!data || loading) {
    return null;
  }

  const someHasBeenPaid = data.some((course) => !!course?.invoiceDate);

  return (
      <Button
        color="secondary"
        disabled={someHasBeenPaid}
        label={t('@app.manager.clientDepartment.invoiceCTA')}
      />
  );
};

实际上,具有invoiceDate 的记录不应该首先被检查。但是复选框是由 react-admin 在内部创建的

【问题讨论】:

    标签: reactjs react-admin


    【解决方案1】:

    根据此文档https://marmelab.com/react-admin/List.html#isrowselectable,您可以在Datagrid 组件上使用isRowSelectable 属性来选择是否可以为批量操作选择行。您可以访问那里的记录,以便根据您的数据做出决定:

    export const RecordList = props => (
        <List {...props}>
            <Datagrid isRowSelectable={ record => !record.invoiceDate }>
                ...
            </Datagrid>
        </List>
    );
    

    【讨论】:

    • 不客气 :) react-admin 的文档非常好,内容也非常丰富,但有时您在阅读它们很多之前都不确定在哪里查看> :)
    • 完全正确 :) 有时你会迷失在其中。但他们最近在文档和框架上都做出了出色的工作和重大改进。再次感谢:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-03
    • 2021-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多