On the assumption I've understood your question correctly, we have done this as follows:
- Extend the data table to support a custom cell data type:
import LightningDatatable from 'lightning/datatable';
import matchCell from './exampleMatchCell.html';
/**
* Extends the lightning-datatable component to add a custom matchScore cell type.
* This custom cell uses a lightning-accordion to show a single collapsible section with an icon.
*/
export default class ExampleResultsTable extends LightningDatatable {
static customTypes = {
matchScore: {
template: matchCell
}
}
}
- Provide the custom cell rendering (exampleMatchCell.html):
<template>
<lightning-accordion allow-multiple-sections-open>
<lightning-accordion-section name="breakdown" label={value.percentage}>
<lightning-icon slot="actions" icon-name={value.icon} variant={value.iconVariant}></lightning-icon>
<template for:each={value.notes} for:item="note">
<p class="slds-truncate" title={note.value} key={note.key}>{note.value}</p>
</template>
</lightning-accordion-section>
</lightning-accordion>
</template>
- Use this custom component in the parent rendering instead of the standard data table:
...
<c-example-results-table
key-field="Id"
data={_results}
columns={_columns}
onrowaction={handleRowActions}
hide-checkbox-column>
</c-example-results-table>
- Have the parent define the columns including the custom type:
...
this._columns.push({
fieldName: 'score',
label: this.Label.ColumnMatch,
type: 'matchScore',
initialWidth: 250,
fixedWidth: undefined,
typeAttributes: {}
});
...
For us, our datatable gets rendered like the following example, where the "Match" column is the one containing an accordion:

The row height adjusts depending on whether the accordion is open or closed, as illustrated.
You will find documentation about handling columns with "custom data types" under "Creating Custom Data Types".