Closed MrVoshel closed 2 years ago
It's not currently supported, but this is a valid feature request.
@MrVoshel Would this API address your use case?
nonExpandableRowIds
to specify ids for rows that should not be expandableCode
<DataTable
expandable
nonExpandableRowIds={["a", "b"]}
headers={[
{ key: "name", value: "Name" },
{ key: "protocol", value: "Protocol" },
{ key: "port", value: "Port" },
{ key: "rule", value: "Rule" },
]}
{rows}
/>
Result
This completely solves my problem, thank you!
I'll keep this open until #862 is merged.
Released in v0.47.0.
"Non-expandable rows" example in the docs.
@metonym it seems to mess up the UI of batchExpansion
a bit when everything is expanded.
<DataTable batchExpansion nonExpandableRowIds={['2']} {headers} {rows}>
<span slot="expanded-row" let:row>
{#if row.id === '1'}
<p>Some details for row {row.id}</p>
{/if}
<!-- I don't have any details for row.id 2, so I want to set
the expandable prop to false -->
{#if row.id === '3'}
<p>Additional details for row {row.id}</p>
{/if}
</span>
</DataTable>
Please be more specific. Expected vs unexpected behavior etc.
This is how it should be but if I use the batchExpansion this is what happens The ID 2 is not clearly separated from the rest. Moreover if I use the batchExpansion to expand everything, but then close each row individually there is another problem Hope that was clear.
What you're describing seems to be the intended design for a batch expandable data table.
This is what I'm seeing locally:
Code:
<script>
import { Grid, DataTable, Row, Column } from "carbon-components-svelte";
const rows = [
{
id: "a",
name: "Load Balancer 3",
protocol: "HTTP",
port: 3000,
rule: "Round robin",
},
{
id: "b",
name: "Load Balancer 1",
protocol: "HTTP",
port: 443,
rule: "Round robin",
},
{
id: "c",
name: "Load Balancer 2",
protocol: "HTTP",
port: 80,
rule: "DNS delegation",
},
{
id: "d",
name: "Load Balancer 6",
protocol: "HTTP",
port: 3000,
rule: "Round robin",
},
{
id: "e",
name: "Load Balancer 4",
protocol: "HTTP",
port: 443,
rule: "Round robin",
},
{
id: "f",
name: "Load Balancer 5",
protocol: "HTTP",
port: 80,
rule: "DNS delegation",
},
];
</script>
<Grid padding>
<Row>
<Column>
<DataTable
batchExpansion
nonExpandableRowIds={["a", "b"]}
headers={[
{ key: "name", value: "Name" },
{ key: "protocol", value: "Protocol" },
{ key: "port", value: "Port" },
{ key: "rule", value: "Rule" },
]}
{rows}
>
<svelte:fragment slot="expanded-row" let:row>
{row.id}
</svelte:fragment>
</DataTable>
</Column>
</Row>
</Grid>
Maybe I can explain it better with a video, let me know if this is intended or not, just seems a bit strange to me.
@MrVoshel Understood – thanks
@MrVoshel Creating a separate issue (#867) to track the batchExpansion "expand all" issue
Is it currently possible to decide which row can be expanded in a DataTable? My issue is that when I specify the
expandable
prop it applies globally, even if I don't really need it.