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

Added support for child containers and initialization after view init #647

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ export class EventExample {
}
```

## Special dragulaOptions for ng2-dragula

+ initAfterView: Allows for delayed initialization of the directive. Binds in Angulars AfterViewInit event.
+ childContainerSelector: Allows the ability to use a child element as the container for drag and drop when access to the element is not possible. Uses querySelector for finding the child element from directives container.

## Special Events for ng2-dragula

| Event Name | Listener Arguments | Event Description |
Expand Down
2 changes: 2 additions & 0 deletions demo/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import { Component, ViewEncapsulation } from '@angular/core';
<repeat-example></repeat-example>

<nested-repeat-example></nested-repeat-example>

<table-example></table-example>
</div>
`,
encapsulation: ViewEncapsulation.None
Expand Down
51 changes: 50 additions & 1 deletion demo/src/app/examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,53 @@ export class NestedRepeatExampleComponent {
];
}

@Component({
selector: 'table-example',
templateUrl: './templates/table-example.html'
})
export class TableExampleComponent {
public constructor(private dragulaService:DragulaService) {
dragulaService.setOptions('table-bag', {
revertOnSpill: true
});
}
}

@Component({
selector: 'table-example-child',
template: `
<table class="table">
<thead>
<tr>
<th></th>
<th>Name</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<tr>
<td><div class="bars"></div></td>
<td>Tester</td>
<td>Active</td>
</tr>
<tr>
<td><div class="bars"></div></td>
<td>James</td>
<td>Active</td>
</tr>
<tr>
<td><div class="bars"></div></td>
<td>Alex</td>
<td>Active</td>
</tr>
</tbody>
</table>`
})
export class TableChildExampleComponent {
public constructor() {
}
}

export const EXAMPLES:any[] = [
ExampleAComponent,
ExampleBComponent,
Expand All @@ -203,5 +250,7 @@ export const EXAMPLES:any[] = [
MuchExampleComponent,
WowExampleComponent,
RepeatExampleComponent,
NestedRepeatExampleComponent
NestedRepeatExampleComponent,
TableExampleComponent,
TableChildExampleComponent
];
46 changes: 46 additions & 0 deletions demo/src/app/templates/table-example.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<div class='parent'>
<label for='hy'>Move table rows when dont have access to child elements</label>
<div class='wrapper'>
<div class="conatiner">
<table-example-child [dragula]='"table-bag"' [dragulaOptions]="{ childContainerSelector: 'tbody', initAfterView: true }">
</table-example-child>
</div>
</div>
<pre>
<code>
&lt;table-example-child [dragula]='"table-bag"' [dragulaOptions]="{{'{'}} childContainerSelector: 'tbody', initAfterView: true {{'}'}}"&gt;
&lt;/table-example-child&gt;

Component(
selector: 'table-example-child',
template: `
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Name&lt;/th&gt;
&lt;th&gt;Status&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Tester&lt;/td&gt;
&lt;td&gt;Active&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;James&lt;/td&gt;
&lt;td&gt;Active&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Alex&lt;/td&gt;
&lt;td&gt;Active&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;`
)
export class TableChildExampleComponent
public constructor()


</code>
</pre>
</div>
Loading