|
1 | 1 | [](https://npmjs.org/package/svelte-data-grid) |
2 | | -# Svelte Data Grid |
| 2 | +# Svelte Data Grid, slightly enhanced |
| 3 | + |
| 4 | +This is a fork of [gamalielmendez's fork](https://github.com/gamalielmendez/svelte-data-grid) |
| 5 | +of [svelte-data-grid](https://github.com/bsssshhhhhhh/svelte-data-grid). |
| 6 | + |
| 7 | +gamalielmendez's fork added: |
| 8 | +- Infinite scroll |
| 9 | +- Ability to select row |
| 10 | +- Move selection cursor with mouse wheel |
| 11 | +- Changecursor event |
| 12 | +- Move cursor with the keyboard arrows |
| 13 | +- Striped rows |
| 14 | + |
| 15 | +This fork added/fixed: |
| 16 | +- Render "" instead of "undefined" if no data |
| 17 | +- Changed `on:change` to `on:blur` per warning message |
| 18 | +- Added tableWidth prop, allow last column to have auto width |
| 19 | +- Fixed input loses focus |
| 20 | +- Added debounce |
| 21 | +- Fixed dispatch |
| 22 | +- Added align prop |
| 23 | +- Lighter border colors |
| 24 | +- Added onCellUpdate and onHeaderUpdate (see usage below) |
3 | 25 |
|
4 | 26 | ## [Demo](https://bsssshhhhhhh.github.io/svelte-data-grid-demo/) |
5 | | - |
| 27 | +### [Demo repo](https://github.com/bsssshhhhhhh/svelte-data-grid-demo) |
6 | 28 |
|
7 | 29 | Svelte Data Grid is a svelte v3 component for displaying and editing any amount of data. |
8 | 30 |
|
@@ -197,6 +219,45 @@ import MyCustomCell from './MyCustomCell.svelte'; |
197 | 219 | ## Custom Header Components |
198 | 220 | Header components can also be specified in `columns` entries as the `headerComponent` property. Header components are only passed `column`, the column object from `columns`. |
199 | 221 |
|
| 222 | +## onCellUpdate, onHeaderUpdate |
| 223 | + |
| 224 | +`on:valueUpdated={handler}` doesn't seem to work for me (at least not for textbox-cell, `event.*` were all `undefined`). |
| 225 | +Thus, `onCellUpdate` callback is added for cell updates. |
| 226 | + |
| 227 | +Likewise,`onHeaderUpdate` callback is added for custom events trigger on a custom header column. Eg. |
| 228 | + |
| 229 | +MyCustomHeaderCol.svelte |
| 230 | +```svelte |
| 231 | +<script> |
| 232 | + export function onUpdate(action) { |
| 233 | + dispatch('update', { |
| 234 | + action, |
| 235 | + }) |
| 236 | + } |
| 237 | +</script> |
| 238 | +
|
| 239 | +<i on:click={evt => onUpdate('someAction')}> |
| 240 | +``` |
| 241 | + |
| 242 | +MyCustomHeaderCol.svelte |
| 243 | +```svelte |
| 244 | +<script> |
| 245 | + $: columns = [ ...otherCols, |
| 246 | + { headerComponent: MyCustomHeaderCol, disallowResize: true }, |
| 247 | + ] |
| 248 | + const onCellUpdate = (event) => { |
| 249 | + const { rowNumber, value } = event.detail |
| 250 | + } |
| 251 | + const onHeaderUpdate = (event) => { |
| 252 | + const { action } = event.detail |
| 253 | + } |
| 254 | +</script> |
| 255 | +<DataGrid {rows} {columns} {...props} {tableWidth} |
| 256 | + {onHeaderUpdate} |
| 257 | + {onCellUpdate} |
| 258 | +/> |
| 259 | +``` |
| 260 | + |
200 | 261 | ## Options: |
201 | 262 |
|
202 | 263 | Svelte Data Grid provides a few options for controlling the grid and its interactions: |
|
0 commit comments