[SalesForce] How to get data from selected rows in a lightning datatable

How can I get data from a row selected in a lightning data table? I was looking at this post but it doesn't seem like the playground linked in the answer is working so I cannot see the helper method. The first answer for that uses a custom table and I would like to stick to using the lightning datatable. Does anyone have any examples? I would like to get the recordId's of the records selected, to be specific.

Best Answer

The playground / lwc documentation has a clear code sample of how to get row selection(s):

    <lightning-datatable
                key-field="id"
                data={data}
                columns={columns}
                onrowaction={handleRowSelection}>
        </lightning-datatable>

    handleRowSelection(event){
            const selectedRows = event.detail.selectedRows
    }