| 3 | import Framework7Class from '../../shared/class.js'; |
| 4 | |
| 5 | class DataTable extends Framework7Class { |
| 6 | constructor(app, params = {}) { |
| 7 | super(params, [app]); |
| 8 | |
| 9 | const table = this; |
| 10 | |
| 11 | const defaults = {}; |
| 12 | |
| 13 | // Extend defaults with modules params |
| 14 | table.useModulesParams(defaults); |
| 15 | |
| 16 | table.params = extend(defaults, params); |
| 17 | |
| 18 | // El |
| 19 | const $el = $(table.params.el); |
| 20 | if ($el.length === 0) return undefined; |
| 21 | |
| 22 | table.$el = $el; |
| 23 | table.el = $el[0]; |
| 24 | |
| 25 | if (table.$el[0].f7DataTable) { |
| 26 | const instance = table.$el[0].f7DataTable; |
| 27 | table.destroy(); |
| 28 | return instance; |
| 29 | } |
| 30 | |
| 31 | table.$el[0].f7DataTable = table; |
| 32 | |
| 33 | extend(table, { |
| 34 | collapsible: $el.hasClass('data-table-collapsible'), |
| 35 | // Headers |
| 36 | $headerEl: $el.find('.data-table-header'), |
| 37 | $headerSelectedEl: $el.find('.data-table-header-selected'), |
| 38 | }); |
| 39 | |
| 40 | // Events |
| 41 | function handleChange(e) { |
| 42 | if (e.detail && e.detail.sentByF7DataTable) { |
| 43 | // Scripted event, don't do anything |
| 44 | return; |
| 45 | } |
| 46 | const $inputEl = $(this); |
| 47 | const checked = $inputEl[0].checked; |
| 48 | const columnIndex = $inputEl.parents('td,th').index(); |
| 49 | |
| 50 | if ($inputEl.parents('thead').length > 0) { |
| 51 | if (columnIndex === 0) { |
| 52 | $el.find('tbody tr')[checked ? 'addClass' : 'removeClass']('data-table-row-selected'); |
| 53 | } |
| 54 | $el |
| 55 | .find(`tbody tr td:nth-child(${columnIndex + 1}) input`) |
| 56 | .prop('checked', checked) |
| 57 | .trigger('change', { sentByF7DataTable: true }); |
| 58 | $inputEl.prop('indeterminate', false); |
| 59 | } else { |
| 60 | if (columnIndex === 0) { |
| 61 | $inputEl.parents('tr')[checked ? 'addClass' : 'removeClass']('data-table-row-selected'); |
| 62 | } |
nothing calls this directly
no outgoing calls
no test coverage detected