File tree 3 files changed +28
-2
lines changed
3 files changed +28
-2
lines changed Original file line number Diff line number Diff line change 170
170
const batchSelectedIds = writable (false );
171
171
const tableRows = writable (rows);
172
172
173
+ // Internal ID prefix for radio buttons, checkboxes, etc.
174
+ // since there may be multiple `DataTable` instances that have overlapping row ids.
175
+ const id = " ccs-" + Math .random ().toString (36 );
176
+
173
177
// Store a copy of the original rows for filter restoration.
174
178
$: originalRows = [... rows];
175
179
499
503
{#if ! nonSelectableRowIds .includes (row .id )}
500
504
{#if radio}
501
505
< RadioButton
502
- name= " select-row -{row.id}"
506
+ name= " {id} -{row.id}"
503
507
checked= {selectedRowIds .includes (row .id )}
504
508
on: change= {() => {
505
509
selectedRowIds = [row .id ];
508
512
/ >
509
513
{: else }
510
514
< InlineCheckbox
511
- name= " select-row -{row.id}"
515
+ name= " {id} -{row.id}"
512
516
checked= {selectedRowIds .includes (row .id )}
513
517
on: change= {() => {
514
518
if (selectedRowIds .includes (row .id )) {
Original file line number Diff line number Diff line change 4
4
import Accordion from " ./Accordion/Accordion.test.svelte" ;
5
5
import AccordionProgrammatic from " ./Accordion/Accordion.programmatic.test.svelte" ;
6
6
import AccordionDisabled from " ./Accordion/Accordion.disabled.test.svelte" ;
7
+ import DuplicateDataTables from " ./DataTable/DuplicateDataTables.test.svelte" ;
7
8
import TreeView from " ./TreeView/TreeView.test.svelte" ;
8
9
import TreeViewHierarchy from " ./TreeView/TreeView.hierarchy.test.svelte" ;
9
10
import RecursiveList from " ./RecursiveList/RecursiveList.test.svelte" ;
32
33
name: " AccordionDisabled" ,
33
34
component: AccordionDisabled ,
34
35
},
36
+ {
37
+ path: " /data-table" ,
38
+ name: " DataTable" ,
39
+ component: DuplicateDataTables ,
40
+ },
35
41
{
36
42
path: " /recursive-list" ,
37
43
name: " RecursiveList" ,
Original file line number Diff line number Diff line change
1
+ <script lang =" ts" >
2
+ import { DataTable } from " carbon-components-svelte" ;
3
+
4
+ const headers = [
5
+ { key: " id" , value: " id" },
6
+ { key: " contact.company" , value: " Company name" },
7
+ ] as const ;
8
+
9
+ const rows = [
10
+ { id: " 1" , contact: { company: " Company 1" } },
11
+ { id: " 2" , contact: { company: " Company 2" } },
12
+ ];
13
+ </script >
14
+
15
+ <DataTable radio {headers } {rows } />
16
+ <DataTable radio {headers } {rows } />
You can’t perform that action at this time.
0 commit comments