Get selected record IDs for custom added admin button

Since there is no answer and I need a solution - everything else for bulk ops is ready, I simply created a very very hacky method which could help some other poor soul :slight_smile: If someone sees this and knows a correct way of doing this in Strapi Admin, I would surely like to know. This is prone to issues if Strapi table structure changes but it is not that hard to update :confused:

What this does is a very basic DOM scrape in order to get IDs - of course, ID column must be shown!

const getCheckedIDs = () => {
    let ids = []
    document.querySelectorAll('input[type="checkbox"]:checked').forEach(c => {
      const elements = c.parentElement.parentElement.querySelectorAll('td[aria-colindex="2"] > span')
      if (elements.length > 0) ids.push(elements[0].textContent)
    })
    console.log("selected ids", ids)
    return ids
  }
2 Likes