Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new 'addable' option #307

Merged
merged 1 commit into from
Apr 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/app/pages/examples/server/basic-example-load.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ export class BasicExampleLoadComponent {
columns: {
id: {
title: 'ID',
editable: false,
addable: false,
},


name: {
title: 'Full Name',
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h2>Get data from external source examples</h2>
<h2>Get data from external source example</h2>
<h3><a id="from-server" class="anchor" href="#from-server" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Loading From Server Example</h3>
<p>
This example shows how to pass the data loaded from some API to the table DataSource.
Expand Down
8 changes: 7 additions & 1 deletion src/ng2-smart-table/lib/data-set/cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ export class Cell {
}

isEditable(): boolean {
return this.getColumn().isEditable;
if (this.getRow().index === -1) {
return this.getColumn().isAddable;
}
else {
return this.getColumn().isEditable;
}
}

}
2 changes: 2 additions & 0 deletions src/ng2-smart-table/lib/data-set/column.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export class Column {
class: string = '';
isSortable: boolean = false;
isEditable: boolean = true;
isAddable: boolean = true;
isFilterable: boolean = false;
sortDirection: string = '';
defaultSortDirection: string = '';
Expand Down Expand Up @@ -58,6 +59,7 @@ export class Column {
.indexOf(this.settings['sortDirection']) !== -1 ? this.settings['sortDirection'] : '';
this.isSortable = typeof this.settings['sort'] === 'undefined' ? true : !!this.settings['sort'];
this.isEditable = typeof this.settings['editable'] === 'undefined' ? true : !!this.settings['editable'];
this.isAddable=typeof this.settings['addable'] === 'undefined' ? true : !!this.settings['addable'];
this.sortDirection = this.prepareSortDirection();

this.compareFunction = this.settings['compareFunction'];
Expand Down
2 changes: 1 addition & 1 deletion src/ng2-smart-table/lib/data-set/data-set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export class DataSet {
}

createNewRow() {
this.newRow = new Row(0, {}, this);
this.newRow = new Row(-1, {}, this);
this.newRow.isInEditing = true;
}

Expand Down