mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
Selection state for dynamic table rows
- visual indication of the selected row - toggling selection of the row
This commit is contained in:
@@ -0,0 +1,23 @@
|
|||||||
|
/*!
|
||||||
|
* @license
|
||||||
|
* Copyright 2016 Alfresco Software, Ltd.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export interface DynamicTableRow {
|
||||||
|
|
||||||
|
selected: boolean;
|
||||||
|
value: any;
|
||||||
|
|
||||||
|
}
|
@@ -19,13 +19,35 @@ import { FormWidgetModel } from './form-widget.model';
|
|||||||
import { FormModel } from './form.model';
|
import { FormModel } from './form.model';
|
||||||
import { FormFieldModel } from './form-field.model';
|
import { FormFieldModel } from './form-field.model';
|
||||||
import { DynamicTableColumn } from './dynamic-table-column';
|
import { DynamicTableColumn } from './dynamic-table-column';
|
||||||
|
import { DynamicTableRow } from './dynamic-table-row';
|
||||||
|
|
||||||
export class DynamicTableModel extends FormWidgetModel {
|
export class DynamicTableModel extends FormWidgetModel {
|
||||||
|
|
||||||
field: FormFieldModel;
|
field: FormFieldModel;
|
||||||
columns: DynamicTableColumn[] = [];
|
columns: DynamicTableColumn[] = [];
|
||||||
visibleColumns: DynamicTableColumn[] = [];
|
visibleColumns: DynamicTableColumn[] = [];
|
||||||
rows: any[] = [];
|
rows: DynamicTableRow[] = [];
|
||||||
|
|
||||||
|
private _selectedRow: DynamicTableRow;
|
||||||
|
|
||||||
|
get selectedRow(): DynamicTableRow {
|
||||||
|
return this._selectedRow;
|
||||||
|
}
|
||||||
|
|
||||||
|
set selectedRow(value: DynamicTableRow) {
|
||||||
|
if (this._selectedRow && this._selectedRow === value) {
|
||||||
|
this._selectedRow.selected = false;
|
||||||
|
this._selectedRow = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.rows.forEach(row => row.selected = false);
|
||||||
|
|
||||||
|
if (value) {
|
||||||
|
this._selectedRow = value;
|
||||||
|
this._selectedRow.selected = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
constructor(form: FormModel, json?: any) {
|
constructor(form: FormModel, json?: any) {
|
||||||
super(form, json);
|
super(form, json);
|
||||||
@@ -38,8 +60,9 @@ export class DynamicTableModel extends FormWidgetModel {
|
|||||||
this.visibleColumns = this.columns.filter(col => col.visible);
|
this.visibleColumns = this.columns.filter(col => col.visible);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.rows = json.value || [];
|
if (json.value) {
|
||||||
|
this.rows = json.value.map(obj => <DynamicTableRow> { selected: false, value: obj });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -29,3 +29,5 @@ export * from './form-outcome.model';
|
|||||||
export * from './form-outcome-event.model';
|
export * from './form-outcome-event.model';
|
||||||
export * from './form-field-validator';
|
export * from './form-field-validator';
|
||||||
export * from './dynamic-table.model';
|
export * from './dynamic-table.model';
|
||||||
|
export * from './dynamic-table-column';
|
||||||
|
export * from './dynamic-table-row';
|
||||||
|
@@ -2,6 +2,11 @@
|
|||||||
padding: 8px;
|
padding: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.dynamic-table-widget__row-selected,
|
||||||
|
.dynamic-table-widget__row-selected:hover {
|
||||||
|
background-color: #eef !important;
|
||||||
|
}
|
||||||
|
|
||||||
.dynamic-table-widget__table {
|
.dynamic-table-widget__table {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
@@ -12,10 +12,12 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr *ngFor="let row of content.rows">
|
<tr *ngFor="let row of content.rows"
|
||||||
|
[class.dynamic-table-widget__row-selected]="row.selected">
|
||||||
<td *ngFor="let column of content.visibleColumns"
|
<td *ngFor="let column of content.visibleColumns"
|
||||||
class="mdl-data-table__cell--non-numeric">
|
class="mdl-data-table__cell--non-numeric"
|
||||||
{{row[column.id]}}
|
(click)="onRowClicked(row)">
|
||||||
|
{{row.value[column.id]}}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
@@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
import { Component, Input, OnInit } from '@angular/core';
|
import { Component, Input, OnInit } from '@angular/core';
|
||||||
import { WidgetComponent } from './../widget.component';
|
import { WidgetComponent } from './../widget.component';
|
||||||
import { DynamicTableModel } from './../core/index';
|
import { DynamicTableModel, DynamicTableRow } from './../core/index';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
moduleId: module.id,
|
moduleId: module.id,
|
||||||
@@ -32,4 +32,10 @@ export class DynamicTableWidget extends WidgetComponent implements OnInit {
|
|||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onRowClicked(row: DynamicTableRow) {
|
||||||
|
if (this.content) {
|
||||||
|
this.content.selectedRow = row;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user