Skip to content

Commit

Permalink
Fixed #2218
Browse files Browse the repository at this point in the history
  • Loading branch information
Çağatay Çivici committed Mar 10, 2017
1 parent 62a060c commit bb1792e
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 8 deletions.
1 change: 1 addition & 0 deletions components/common/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export interface TreeNode {
styleClass?: string;
draggable?: boolean;
droppable?: boolean;
selectable?: boolean;
}

export interface Confirmation {
Expand Down
2 changes: 1 addition & 1 deletion components/tree/tree.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
width: 18em;
}

.ui-tree.ui-tree-selectable .ui-treenode-content {
.ui-tree .ui-treenode-selectable.ui-treenode-content {
cursor: pointer;
}

Expand Down
11 changes: 8 additions & 3 deletions components/tree/tree.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {NgModule,Component,Input,AfterContentInit,OnDestroy,Output,EventEmitter,OnInit,OnDestroy,EmbeddedViewRef,ViewContainerRef,
import {NgModule,Component,Input,AfterContentInit,OnDestroy,Output,EventEmitter,OnInit,EmbeddedViewRef,ViewContainerRef,
ContentChildren,QueryList,TemplateRef,Inject,forwardRef,Host} from '@angular/core';
import {CommonModule} from '@angular/common';
import {TreeNode} from '../common/api';
Expand Down Expand Up @@ -41,7 +41,7 @@ export class TreeNodeTemplateLoader implements OnInit, OnDestroy {
<li class="ui-treenode {{node.styleClass}}" *ngIf="!tree.horizontal" [ngClass]="{'ui-treenode-leaf': isLeaf()}">
<div class="ui-treenode-content" (click)="onNodeClick($event)" (contextmenu)="onNodeRightClick($event)" (touchend)="onNodeTouchEnd()"
(drop)="onDropNode($event)" (dragover)="onDropNodeDragOver($event)" (dragenter)="onDropNodeDragEnter($event)" (dragleave)="onDropNodeDragLeave($event)"
[ngClass]="{'ui-treenode-selectable':tree.selectionMode,'ui-treenode-dragover':draghoverNode}" [draggable]="tree.draggableNodes" (dragstart)="onDragStart($event)" (dragend)="onDragStop($event)">
[ngClass]="{'ui-treenode-selectable':tree.selectionMode && node.selectable !== false,'ui-treenode-dragover':draghoverNode}" [draggable]="tree.draggableNodes" (dragstart)="onDragStart($event)" (dragend)="onDragStop($event)">
<span class="ui-tree-toggler fa fa-fw" [ngClass]="{'fa-caret-right':!node.expanded,'fa-caret-down':node.expanded}"
(click)="toggle($event)"></span
><div class="ui-chkbox" *ngIf="tree.selectionMode == 'checkbox'"><div class="ui-chkbox-box ui-widget ui-corner-all ui-state-default">
Expand Down Expand Up @@ -426,7 +426,12 @@ export class Tree implements OnInit,AfterContentInit,OnDestroy {
if(eventTarget.className && eventTarget.className.indexOf('ui-tree-toggler') === 0) {
return;
}
else {
else if(this.selectionMode) {
console.log(node);
if(node.selectable === false) {
return;
}

let index = this.findIndexInSelection(node);
let selected = (index >= 0);

Expand Down
8 changes: 6 additions & 2 deletions components/treetable/treetable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {DomHandler} from '../dom/domhandler';
@Component({
selector: '[pTreeRow]',
template: `
<div class="ui-treetable-row" [ngClass]="{'ui-state-highlight':isSelected(),'ui-treetable-row-selectable':treeTable.selectionMode}">
<div class="ui-treetable-row" [ngClass]="{'ui-state-highlight':isSelected(),'ui-treetable-row-selectable':treeTable.selectionMode && node.selectable !== false}">
<td *ngFor="let col of treeTable.columns; let i=index" [ngStyle]="col.style" [class]="col.styleClass" (click)="onRowClick($event)" (touchend)="onRowTouchEnd()">
<a href="#" *ngIf="i==0" class="ui-treetable-toggler fa fa-fw ui-c" [ngClass]="{'fa-caret-down':node.expanded,'fa-caret-right':!node.expanded}"
[ngStyle]="{'margin-left':level*16 + 'px','visibility': isLeaf() ? 'hidden' : 'visible'}"
Expand Down Expand Up @@ -176,7 +176,11 @@ export class TreeTable {
if(eventTarget.className && eventTarget.className.indexOf('ui-treetable-toggler') === 0) {
return;
}
else {
else if(this.selectionMode) {
if(node.selectable === false) {
return;
}

let metaSelection = this.rowTouched ? false : this.metaKeySelection;
let index = this.findIndexInSelection(node);
let selected = (index >= 0);
Expand Down
12 changes: 10 additions & 2 deletions showcase/demo/tree/treedemo.html
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,17 @@ <h3>Getting Started</h3>
<td>Whether to disable dragging for a particular node even if draggableNodes is enabled.</td>
</tr>
<tr>
<td>styleClass</td>
<td>string</td>
<td>droppable</td>
<td>boolean</td>
<td>null</td>
<td>Whether to disable dropping for a particular node even if droppableNodes is enabled.</td>
</tr>
<tr>
<td>selectable</td>
<td>boolean</td>
<td>null</td>
<td>Used to disable selection of a particular node.</td>
</tr>
</tbody>
</table>
</div>
Expand Down Expand Up @@ -395,6 +401,8 @@ <h3>Selection</h3>
</code>
</pre>

<p>Selection of a particular node can be disabled by setting the selectable property of the node to false.</p>

<h3>Icons</h3>
<p>Icon of a treenode is defined using the icon property, if you need an icon depending on the expand or collapse state, use
expandedIcon and collapsedIcon instead.</p>
Expand Down
2 changes: 2 additions & 0 deletions showcase/demo/treetable/treetabledemo.html
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,8 @@ <h3>Selection</h3>
&#125;
</code>
</pre>

<p>Selection of a particular node can be disabled by setting the selectable property of the node to false.</p>

<h3>Templating</h3>
<p>By default label of a treenode is displayed inside a tree node, in case you need to place custom content define a ng-template inside a column that gets
Expand Down

0 comments on commit bb1792e

Please sign in to comment.