Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix resizing columns issues #1

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions addon/components/lt-column-resizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,17 @@ export default Component.extend({
let index = this.get('table.visibleColumns').indexOf(this.get('column')) + 1;
let table = closest(this.get('element'), TOP_LEVEL_CLASS);

column.width = width;
table.querySelector(`thead td.lt-scaffolding:nth-child(${index})`).style.width = width;
table.querySelector(`tfoot td.lt-scaffolding:nth-child(${index})`).style.width = width;
column.style.width = width;
const headerScaffoldingCell = table.querySelector(`thead td.lt-scaffolding:nth-child(${index})`);
if (headerScaffoldingCell) {
headerScaffoldingCell.style.width = width;
}

const footerScaffoldingCell = table.querySelector(`tfoot td.lt-scaffolding:nth-child(${index})`);
if (footerScaffoldingCell) {
footerScaffoldingCell.style.width = width;
}

if (resizeOnDrag) {
let cols = table.querySelectorAll(`tbody td:nth-child(${index})`);
cols.forEach((col) => {
Expand Down
8 changes: 8 additions & 0 deletions addon/components/lt-scaffolding-row.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Component from '@ember/component';
import layout from '../templates/components/lt-scaffolding-row';

export default Component.extend({
classNames: ['lt-scaffolding-row'],
layout,
tagName: 'tr'
});
8 changes: 1 addition & 7 deletions addon/templates/components/lt-foot.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@
<table class={{tableClassNames}}>
<tfoot class="lt-foot">
{{!-- Scaffolding is needed here to allow use of colspan in the footer --}}
<tr class="lt-scaffolding-row">
{{#each columns as |column|}}
{{! template-lint-disable no-inline-styles }}
<td style={{html-safe (if column.width (concat "width: " column.width))}} class="lt-scaffolding"></td>
{{! template-lint-enable no-inline-styles }}
{{/each}}
</tr>
{{lt-scaffolding-row columns=columns}}
{{#if hasBlock}}
{{yield columns}}
{{else}}
Expand Down
10 changes: 3 additions & 7 deletions addon/templates/components/lt-head.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,9 @@
the td's fail to hold their width. Creating a scaffolding will setup the table columns correctly
--}}
{{#if subColumns.length}}
<tr class="lt-scaffolding-row">
{{#each subColumns as |column|}}
{{! template-lint-disable no-inline-styles }}
<td style={{html-safe (if column.width (concat "width: " column.width))}} class="lt-scaffolding"></td>
{{! template-lint-enable no-inline-styles }}
{{/each}}
</tr>
{{lt-scaffolding-row columns=subColumns}}
{{else}}
{{lt-scaffolding-row columns=columnGroups}}
{{/if}}

<tr>
Expand Down
5 changes: 5 additions & 0 deletions addon/templates/components/lt-scaffolding-row.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{{#each columns as |column|}}
{{! template-lint-disable no-inline-styles }}
<td style={{html-safe (if column.width (concat "width: " column.width))}} class="lt-scaffolding"></td>
{{! template-lint-enable no-inline-styles }}
{{/each}}
1 change: 1 addition & 0 deletions app/components/lt-scaffolding-row.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from 'ember-light-table/components/lt-scaffolding-row';
48 changes: 48 additions & 0 deletions tests/integration/components/lt-scaffolding-row-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render, find, findAll } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';

module('Integration | Component | lt-scaffolding-row', function(hooks) {
setupRenderingTest(hooks);

test('it has lt-scaffolding-row class', async function(assert) {
await render(hbs`{{lt-scaffolding-row}}`);
assert.ok(find('.lt-scaffolding-row'));
});

test('it renders <tr>', async function(assert) {
await render(hbs`{{lt-scaffolding-row}}`);
assert.ok(find('tr'));
});

test('it renders <td> for each column', async function(assert) {
const columns = [{
label: 'Avatar',
valuePath: 'avatar',
width: '60px',
sortable: false,
cellComponent: 'user-avatar'
}, {
label: 'First Name',
valuePath: 'firstName',
width: '150px'
}, {
label: 'Last Name',
valuePath: 'lastName',
width: '150px'
}, {
label: 'Address',
valuePath: 'address'
}, {
label: 'State',
valuePath: 'state'
}, {
label: 'Country',
valuePath: 'country'
}];
this.set('columns', columns);
await render(hbs`{{lt-scaffolding-row columns=columns}}`);
assert.equal(findAll('td').length, columns.length);
});
});