Reactivity example with a simple CRUD
ID | First name | Last name | Email | |
---|---|---|---|---|
1 | Sallyann | Curnnokk | scurnnokk0@fc2.com | |
2 | Alix | Lavigne | alavigne1@telegraph.co.uk | |
3 | Belia | Gorman | bgorman2@odnoklassniki.ru | |
4 | Wes | Gullyes | wgullyes3@netscape.com | |
5 | Karlyn | Halt | khalt4@upenn.edu | |
6 | Meggi | Younge | myounge5@blogs.com | |
7 | Douglass | Kynd | dkynd6@godaddy.com | |
8 | Jesse | Pattemore | jpattemore7@mozilla.org | |
9 | Etti | Gowrich | egowrich8@google.ca | |
10 | Meaghan | Petrina | mpetrina9@merriam-webster.com | |
11 | Valentino | Barajas | vbarajasa@wikispaces.com | |
12 | Abba | Merring | amerringb@jimdo.com | |
13 | Nat | Thoresbie | nthoresbiec@google.com.br | |
14 | Lexine | Blunt | lbluntd@bizjournals.com | |
15 | Barbara-anne | Terris | bterrise@acquirethisname.com | |
16 | Herbert | Van der Linde | hvanderlindef@live.com | |
17 | Viviene | Peaddie | vpeaddieg@google.co.jp | |
18 | Stearne | Howchin | showchinh@yolasite.com | |
19 | Evonne | Whannel | ewhanneli@wired.com | |
20 | Agnola | Collishaw | acollishawj@unc.edu |
Auto update rows :
<script lang="ts">
import { Datahandler } from '@vincjo/datatables'
export let myData
const handler = new DataHandler(myData, { rowsPerPage: 20 })
$: myData, handler.setRows(myData)
</script>
Keeping scroll top state :
<script lang="ts">
import { Datahandler } from '@vincjo/datatables'
export let myData
let tableElement: HTMLElement | undefined
const handler = new DataHandler(myData, { rowsPerPage: 20 })
$: myData, update()
const update = () => {
if (tableElement) {
const scrollTop = tableElement.parentNode.scrollTop
handler.setRows(myData)
setTimeout(() => {
tableElement.parentNode.scrollTop = scrollTop
}, 2)
}
}
</script>
<Datatable {handler}>
<table bind:this={tableElement}>
[...]
</table>
</Datatable>