File tree Expand file tree Collapse file tree 3 files changed +26
-4
lines changed Expand file tree Collapse file tree 3 files changed +26
-4
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import { data, Bird } from './birds';
44import { capitalize } from 'lodash-es' ;
55
66const NETWORK_DELAY = 500 ;
7+ type BirdRow = Bird & { id : string } ;
78
89/**
910 * Remote sorting and pagination
@@ -19,9 +20,9 @@ export class TableExampleRemote {
1920 private columns : Array < Column < Bird > > = [ ] ;
2021
2122 @State ( )
22- private currentData : object [ ] = [ ] ;
23+ private currentData : BirdRow [ ] = [ ] ;
2324
24- private allData : object [ ] = data ;
25+ private allData : Bird [ ] = data ;
2526
2627 private pageSize = 10 ;
2728
@@ -106,7 +107,15 @@ export class TableExampleRemote {
106107 setTimeout ( ( ) => {
107108 const start = ( this . currentPage - 1 ) * this . pageSize ;
108109 const end = start + this . pageSize ;
109- this . currentData = this . allData . slice ( start , end ) ;
110+
111+ this . currentData = this . allData
112+ . slice ( start , end )
113+ . map ( ( item , index ) => ( {
114+ ...item ,
115+ // Provide a stable id to keep scroll position and selection
116+ // intact while the remote dataset refreshes.
117+ id : `${ item . binominalName } -${ start + index } ` ,
118+ } ) ) ;
110119 } , NETWORK_DELAY ) ;
111120 }
112121
Original file line number Diff line number Diff line change @@ -3,6 +3,18 @@ import { Column } from '@limetech/lime-elements';
33import { Person , persons } from './persons' ;
44
55/**
6+ * Basic example
7+ *
8+ * :::note
9+ * Each object is recommended to expose a stable `id` (string or number).
10+ * The table relies on that identifier to update rows in place so that
11+ * scroll position, focus, and selections remain intact across renders.
12+ *
13+ * Rows without an `id` are treated as new data on every update.
14+ * Therefore if the user clicks on a row at the bottom of the table,
15+ * it will be treated as new data and will force a full redraw,
16+ * resulting in the table to scroll to the top again.
17+ * :::
618 *
719 * @sourceFile persons.ts
820 */
Original file line number Diff line number Diff line change @@ -51,7 +51,8 @@ const FIRST_PAGE = 1;
5151} )
5252export class Table {
5353 /**
54- * Data to be displayed in the table
54+ * Data to be displayed in the table. Provide a stable `id` on each row to keep
55+ * scroll position, focus, and selections intact across updates.
5556 */
5657 @Prop ( )
5758 public data : object [ ] = [ ] ;
You can’t perform that action at this time.
0 commit comments