Skip to content
This repository has been archived by the owner on Jun 5, 2024. It is now read-only.

Commit

Permalink
feat: add default options for idField, textField & childrenField
Browse files Browse the repository at this point in the history
  • Loading branch information
Hervé TINANT committed Jul 13, 2017
1 parent 55d172c commit 2e6a6c1
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/demo/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { NgxTreeSelectModule } from 'ngx-tree-select';
import { Ng2BootstrapModule } from 'ngx-bootstrap';

import { AppComponent } from './app.component';
import { FlatComponent } from "app/components/flat.component";
import { FlatComponent } from "./components/flat.component";
import { HierarchicalComponent } from './components/hierarchical.component';
import { AppRoutes } from './app.routes';

Expand All @@ -16,7 +16,7 @@ import { AppRoutes } from './app.routes';
FormsModule,
RouterModule.forRoot(AppRoutes),
Ng2BootstrapModule.forRoot(),
NgxTreeSelectModule.forRoot({ filterPlaceholder: 'test', maxVisibleItemCount: 3 })
NgxTreeSelectModule.forRoot({ idField: 'id', textField: 'name' })
],
declarations: [
AppComponent,
Expand Down
4 changes: 0 additions & 4 deletions src/demo/app/components/flat.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ <h1>Exemple ngx-tree-select with flat datas</h1>
<form novalidate>
<tree-select name="simpleSelect"
[items]="items"
idField="id"
textField="name"
childrenField="children"
[(ngModel)]="simpleSelected"
required=true
Expand All @@ -33,8 +31,6 @@ <h1>Exemple ngx-tree-select with flat datas</h1>
<form novalidate>
<tree-select name="multipleSelect"
[items]="items"
idField="id"
textField="name"
childrenField="children"
[multiple]="true"
[(ngModel)]="multipleSelected"
Expand Down
3 changes: 3 additions & 0 deletions src/lib/src/component/tree-select.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ export class TreeSelectComponent implements ControlValueAccessor {
defaultOpts.allowFilter
);
this.filterPlaceholder = (defaultOpts.filterPlaceholder || 'Type here for filtering items...');
this.idField = (defaultOpts.idField || 'id');
this.textField = (defaultOpts.textField || 'id');
this.childrenField = (defaultOpts.childrenField || '');
}

keyUp($event: any) { }
Expand Down
3 changes: 3 additions & 0 deletions src/lib/src/model/tree-select-default-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ export class TreeSelectDefaultOptions {
public filterPlaceholder?: string;
public maxVisibleItemCount?: number;
public allowParentSelection?: boolean;
public idField?: string;
public textField?: string;
public childrenField?: string;
}

0 comments on commit 2e6a6c1

Please sign in to comment.