简体   繁体   English

react-admin:如何自定义批量操作

[英]react-admin: how to customise the bulk actions

I would like to disabled some checkbox created by a custom BulkActionsButton.我想禁用一些由自定义 BulkActionsButton 创建的复选框。 This is a simple list:这是一个简单的列表:

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

and the BulkActionButton :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')}
      />
  );
};

Actually the records which have a invoiceDate should not be checkable first.实际上,不应首先检查具有invoiceDate的记录。 But the checkboxes are created internally by react-admin I don't find any documentation on how to apply some filters to enable/disabled the checkboxes or if it is even possible.但是复选框是由 react-admin 在内部创建的,我没有找到任何关于如何应用某些过滤器来启用/禁用复选框或是否可能的文档。

Based on this documentation https://marmelab.com/react-admin/List.html#isrowselectable you can use isRowSelectable prop on the Datagrid component to choose if a row is selectable for bulk actions.基于此文档https://marmelab.com/react-admin/List.html#isrowselectable,您可以在Datagrid组件上使用isRowSelectable来选择是否可以选择一行进行批量操作。 You get access to the record there so you can make the decision based on your data:您可以访问那里的记录,以便您可以根据您的数据做出决定:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM