mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
Add new record (dynamic table)
This commit is contained in:
@@ -105,11 +105,20 @@ export class DynamicTableModel extends FormWidgetModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addRow(row: DynamicTableRow) {
|
||||||
|
if (row) {
|
||||||
|
this.rows.push(row);
|
||||||
|
// this.selectedRow = row;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
getCellValue(row: DynamicTableRow, column: DynamicTableColumn): any {
|
getCellValue(row: DynamicTableRow, column: DynamicTableColumn): any {
|
||||||
let result = row.value[column.id];
|
let result = row.value[column.id];
|
||||||
|
|
||||||
if (column.type === 'Dropdown') {
|
if (column.type === 'Dropdown') {
|
||||||
return result.name;
|
if (result) {
|
||||||
|
return result.name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (column.type === 'Boolean') {
|
if (column.type === 'Boolean') {
|
||||||
|
@@ -70,7 +70,11 @@ export class DynamicTableWidget extends WidgetComponent implements OnInit {
|
|||||||
|
|
||||||
addNewRow() {
|
addNewRow() {
|
||||||
if (this.content) {
|
if (this.content) {
|
||||||
this.editRow = <DynamicTableRow> { selected: false, value: {} };
|
this.editRow = <DynamicTableRow> {
|
||||||
|
isNew: true,
|
||||||
|
selected: false,
|
||||||
|
value: {}
|
||||||
|
};
|
||||||
this.editMode = true;
|
this.editMode = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -92,7 +96,10 @@ export class DynamicTableWidget extends WidgetComponent implements OnInit {
|
|||||||
onSaveChanges() {
|
onSaveChanges() {
|
||||||
if (this.content) {
|
if (this.content) {
|
||||||
if (this.editRow.isNew) {
|
if (this.editRow.isNew) {
|
||||||
// TODO: create new record
|
let row = this.copyRow(this.editRow);
|
||||||
|
this.content.selectedRow = null;
|
||||||
|
this.content.addRow(row);
|
||||||
|
this.editRow.isNew = false;
|
||||||
} else {
|
} else {
|
||||||
this.content.selectedRow.value = this.copyObject(this.editRow.value);
|
this.content.selectedRow.value = this.copyObject(this.editRow.value);
|
||||||
}
|
}
|
||||||
|
@@ -37,10 +37,14 @@ export class DateEditorComponent extends CellEditorComponent implements OnInit {
|
|||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
let settings: any = {
|
let settings: any = {
|
||||||
type: 'date',
|
type: 'date',
|
||||||
future: moment().add(21, 'years'),
|
future: moment().add(21, 'years')
|
||||||
init: moment(this.table.getCellValue(this.row, this.column), this.DATE_FORMAT)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let value = this.table.getCellValue(this.row, this.column);
|
||||||
|
if (value) {
|
||||||
|
settings.init = moment(value, this.DATE_FORMAT);
|
||||||
|
}
|
||||||
|
|
||||||
this.datePicker = new mdDateTimePicker.default(settings);
|
this.datePicker = new mdDateTimePicker.default(settings);
|
||||||
if (this.elementRef) {
|
if (this.elementRef) {
|
||||||
this.datePicker.trigger = this.elementRef.nativeElement.querySelector('#dateInput');
|
this.datePicker.trigger = this.elementRef.nativeElement.querySelector('#dateInput');
|
||||||
|
@@ -5,6 +5,7 @@
|
|||||||
[value]="table.getCellValue(row, column)"
|
[value]="table.getCellValue(row, column)"
|
||||||
class="dropdown-editor__select"
|
class="dropdown-editor__select"
|
||||||
(change)="onValueChanged(row, column, $event)">
|
(change)="onValueChanged(row, column, $event)">
|
||||||
|
<option></option>
|
||||||
<option *ngFor="let opt of column.options" [value]="opt.name">{{opt.name}}</option>
|
<option *ngFor="let opt of column.options" [value]="opt.name">{{opt.name}}</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user