Add new record (dynamic table)

This commit is contained in:
Denys Vuika
2016-10-21 17:16:04 +01:00
committed by Vito Albano
parent 51102980df
commit 36dd42b62d
4 changed files with 26 additions and 5 deletions

View File

@@ -105,12 +105,21 @@ export class DynamicTableModel extends FormWidgetModel {
}
}
addRow(row: DynamicTableRow) {
if (row) {
this.rows.push(row);
// this.selectedRow = row;
}
}
getCellValue(row: DynamicTableRow, column: DynamicTableColumn): any {
let result = row.value[column.id];
if (column.type === 'Dropdown') {
if (result) {
return result.name;
}
}
if (column.type === 'Boolean') {
return result ? true : false;

View File

@@ -70,7 +70,11 @@ export class DynamicTableWidget extends WidgetComponent implements OnInit {
addNewRow() {
if (this.content) {
this.editRow = <DynamicTableRow> { selected: false, value: {} };
this.editRow = <DynamicTableRow> {
isNew: true,
selected: false,
value: {}
};
this.editMode = true;
}
}
@@ -92,7 +96,10 @@ export class DynamicTableWidget extends WidgetComponent implements OnInit {
onSaveChanges() {
if (this.content) {
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 {
this.content.selectedRow.value = this.copyObject(this.editRow.value);
}

View File

@@ -37,10 +37,14 @@ export class DateEditorComponent extends CellEditorComponent implements OnInit {
ngOnInit() {
let settings: any = {
type: 'date',
future: moment().add(21, 'years'),
init: moment(this.table.getCellValue(this.row, this.column), this.DATE_FORMAT)
future: moment().add(21, 'years')
};
let value = this.table.getCellValue(this.row, this.column);
if (value) {
settings.init = moment(value, this.DATE_FORMAT);
}
this.datePicker = new mdDateTimePicker.default(settings);
if (this.elementRef) {
this.datePicker.trigger = this.elementRef.nativeElement.querySelector('#dateInput');

View File

@@ -5,6 +5,7 @@
[value]="table.getCellValue(row, column)"
class="dropdown-editor__select"
(change)="onValueChanged(row, column, $event)">
<option></option>
<option *ngFor="let opt of column.options" [value]="opt.name">{{opt.name}}</option>
</select>
</div>