Skip to content
New issue

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

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

Already on GitHub? # to your account

can't get all selections when pagination changed #44

Open
zhoukekestar opened this issue Mar 24, 2021 · 1 comment
Open

can't get all selections when pagination changed #44

zhoukekestar opened this issue Mar 24, 2021 · 1 comment

Comments

@zhoukekestar
Copy link
Contributor

zhoukekestar commented Mar 24, 2021

See demo: https://codesandbox.io/s/blissful-fog-ixhix

Note: Maybe antd's limitations.

@zhoukekestar
Copy link
Contributor Author

Here is a temporary solution:

import { ListLifeCycleTypes } from '@alist/antd';

export default ($, actions) => {
  console.log($, actions);
  let crossPaginationSelectedRecords = new Set();

  $(ListLifeCycleTypes.ON_LIST_MOUNTED).subscribe((payload) => {
    // enable selection feature
    actions.setRowSelection({ ids: [2] }); 
  });

  $(ListLifeCycleTypes.ON_LIST_SELECT_CHANGE).subscribe((payload) => {

    console.log("ON_LIST_SELECT_CHANGE", payload);

    try {
      // remove current page's record
      actions.getDataSource().map(t => t.id).forEach(item => {
        crossPaginationSelectedRecords.delete(item);
      });
  
      // add current page's payload
      payload.ids.forEach(id => crossPaginationSelectedRecords.add(id));
  
      console.log('crossPaginationSelectedRecords => ', crossPaginationSelectedRecords)
    } catch(err) {
      console.log(err);
    }
    
  });

  // https://github.com/alibaba/alist/issues/44
  $(ListLifeCycleTypes.WILL_LIST_UPDATE).subscribe(() => {
    // manually set
    actions.crossPaginationSelectedRecords = crossPaginationSelectedRecords;
    actions.setRowSelection({ ids: Array.from(crossPaginationSelectedRecords) });
    console.log('WILL_LIST_UPDATE', actions.getRowSelection().records.map(t => t.id), crossPaginationSelectedRecords);
  });
};

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant