How to unselect checkboxes after bulk action execution?

一个人想着一个人 提交于 2019-12-24 10:37:33

问题


On a List module, I created a bulk action button to generate PDF by calling a custom action. The problem is <Datagrid> checkboxes are not unselected once the action is executed.

Here is my custom action:

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',
      },
    },
  },
});

And here is my button:

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>
    );
  }
}

I'm using react-admin 2.3.0, but it wasn't working with previous versions either.

I think the checkboxes are not unchecked because the service I call doesn't update data. Am I right?

Do I have to call another service or action to uncheck them, or am I missing something?


回答1:


You can add this onSuccess side effect parameter unselectAll: true that we should document (please open an issue for it):

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',
      },
    },
  },
});


来源:https://stackoverflow.com/questions/52280137/how-to-unselect-checkboxes-after-bulk-action-execution

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!