【问题标题】:How to unselect checkboxes after bulk action execution?批量操作执行后如何取消选中复选框?
【发布时间】:2019-02-16 04:58:27
【问题描述】:

在 List 模块上,我创建了一个批量操作按钮,通过调用自定义操作来生成 PDF。 问题是<Datagrid> 复选框在执行操作后不会取消选中。

这是我的自定义操作:

export const print = (resource, ids, data) => ({
  type: DOWNLOAD,
  payload: {
    id: ids.length === 1 ? ids[0] : ids,
    data,
  },
  meta: {
    resource: resource,
    fetch: PRINT,
    onFailure: {
      notification: {
        body: 'ra.notification.http_error',
        level: 'warning',
      },
    },
  },
});

这是我的按钮:

class PrintBulkButton extends React.Component {
  handleClick = () => {
    const { basePath, options, print, resource, selectedIds } = this.props;

    print(resource, selectedIds, options, basePath);
  };

  render() {
    return (
      <Button {...sanitizeRestProps(this.props)} onClick={this.handleClick}>
        {this.props.icon}
      </Button>
    );
  }
}

我正在使用 react-admin 2.3.0,但它也不适用于以前的版本。

我认为复选框没有被取消选中,因为我调用的服务不会更新数据。 我说的对吗?

我是否必须调用其他服务或操作来取消选中它们,或者我错过了什么?

【问题讨论】:

    标签: datagrid react-admin


    【解决方案1】:

    您可以添加我们应该记录的onSuccess 副作用参数unselectAll: true(请为此打开一个问题):

    export const print = (resource, ids, data) => ({
      type: DOWNLOAD,
      payload: {
        id: ids.length === 1 ? ids[0] : ids,
        data,
      },
      meta: {
        resource: resource,
        fetch: PRINT,
        onSuccess: {
            unselectAll: true,
        },
        onFailure: {
          notification: {
            body: 'ra.notification.http_error',
            level: 'warning',
          },
        },
      },
    });
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-13
    • 1970-01-01
    相关资源
    最近更新 更多