As mentioned above, the content function is lazily executed when a row is expanded to prevent creating unnecessary DOM elements. If your row expansion content needs to show data that comes from outside the table records, you could exploit this behavior to lazy-load it only when a row is expanded:
You can control the row expansion feature by pointing the rowExpansion/expanded property to an object containing:
recordIds → an array containing the currently expanded record IDs
onRecordIdsChange → a callback function that gets called when the currently expanded records change
When using the row expansion feature in controlled mode, if you want to prevent the default behavior of toggling the expansion state on click, set the rowExpansion/trigger property to 'never'.
{ accessor:'number', title:'#',render:(_, index)=> index +1},
{ accessor:'name', width:'100%'},
{ accessor:'city', ellipsis:true},
{ accessor:'state'},
]}
records={records}
rowExpansion={{
// trigger: 'never', // 👈 uncomment this if you want to disable expanding/collapsing on click
allowMultiple:true,
expanded:{
recordIds: expandedRecordIds,
onRecordIdsChange: setExpandedRecordIds,
},
content:({ record })=>(
// expansion content...
),
}}
/>
</>
);
If you need to combine the row expansion behavior with links, buttons, row action cells or any kind of clickable components inside cells, make sure to intercept the click event on those components and invoke its .stopPropagation() method. See this example for more information.
Head over to the next example to see how you can abuse the row expansion feature to display nested tables.