Getting the IDs of selected items in Content Manager

How can I get the IDs of selected items in the Content Manager from a Strapi plugin?

I tried using useCMEditViewDataManager from "@strapi/helper-plugin" but there is no luck.

System Information
  • Strapi Version: 4.4.5

Isn’t the ID passed into the view :thinking: I haven’t tinkered to much with the UI so I’m not to sure.
I would look at maybe some plugins that does the same thing and see how they do it :thinking: ?

I’m not sure which plugin does this already. This is my actual code. I’m trying to fetch data from useCMEditViewDataManager on button click. The button is present in the "listView", "actions" injection zone.

I believe the selected item data will be available in the modifiedData so I’m destructuring it.

import React from "react";
import { Button } from "@strapi/design-system/Button";
import CheckCircle from "@strapi/icons/CheckCircle";
import { useCMEditViewDataManager } from "@strapi/helper-plugin";

export const MyButton = () => {
  const { modifiedData } = useCMEditViewDataManager();

  const handleClick = () => {
    // Get the IDs of selected entries
    console.log(modifiedData);
  };

  return (
    <Button
      startIcon={<CheckCircle />}
      variant="success-light"
      onClick={() => handleClick}
    >
      Action Button
    </Button>
  );
};

TypeError: Cannot destructure property 'modifiedData' of '(0 , g.useCMEditViewDataManager)(...)' as it is undefined.

Anybody else faced similar issue before? Or any ideas?

Try not destructure it try just log it out and you will see what’s inside of it :thinking:

1 Like

I was getting some errors. For now, I’m using this as a workaround.

But it’ll be really good if the Strapi Developer documentation is updated with this kind of stuff.

1 Like

it is logging undefined.
I am also facing the same problem

Hi @Harsh-bhai

Here is a workaround. With js fetch all the IDs and use them.