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,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;
|
||||
|
@@ -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);
|
||||
}
|
||||
|
@@ -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');
|
||||
|
@@ -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>
|
||||
|
Reference in New Issue
Block a user