akveo / akveo/ng2-smart-table

find and update methods not working.

Đang mở
#129 2 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
TypeScript
Star
1.6k
Fork
867
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

this.userUpdated= this.source.find(p); is not working.

i need your help now. please send me a sloution. I want to update my row after i edit from database

this.source.update(this.userUpdated, this.model);

it throws this exception:
EXCEPTION: Uncaught (in promise): Error: Element was not found in the dataset
Error: Element was not found in the dataset

my codes:

import { Component, OnInit, ViewChild, ViewEncapsulation } from '@angular/core';
import {User} from '../../model/user';
import {UserService} from '../../shared/user/user.service';
import { Ng2SmartTableModule, LocalDataSource } from 'ng2-smart-table';
import { ModalComponent } from 'ng2-bs3-modal/ng2-bs3-modal';

@Component({
selector: 'app-adduser',
templateUrl: './adduser.component.html',
styleUrls: ['./adduser.component.css']
})
export class AdduserComponent implements OnInit {
@ViewChild('validationModal')
modal: ModalComponent;
user: User;
model: User = new User();
userUpdated: User= new User();
selected: string;
output: string;
userId: number;
actionType: number;
index: number = 0;
backdropOptions = [true, false, 'static'];
cssClass: string = '';

animation: boolean = true;
keyboard: boolean = true;
backdrop: string | boolean = true;
css: boolean = false;

close() {
this.modal.close();
}

closed() {
this.output = '(closed) ' + this.selected;
console.log("hps:" + this.output);
}

errorMessage = "user listeleme sayfası";
userList: User[] = [];

settings = {

edit: {
confirmEdit: true
},

delete: {
confirmDelete: true
},
columns: {
id: {
title: 'ID'
},
name: {
title: 'Full Name'
},
surname: {
title: 'Surname'
},
username: {
title: 'User Name'
},
email: {
title: 'Email'
}
}
};
source: LocalDataSource;
constructor(private userService: UserService) {
this.source = new LocalDataSource(this.userList); // create the source
this.actionType = 0;

}

//p => this.userList = p
ngOnInit() {
console.log("user componant içi");
this.userService
.listUsers()
.subscribe(p => this.source.load(p))
}
newPost() {
this.actionType = 1;//it means create
this.modal.open();

}


onSelectRow(event): void {

this.userId = event.data.id;
this.userService
.findUserById(this.userId)
.subscribe(p => {
this.model = p;
this.userUpdated= this.source.find(p);
console.log(this.userUpdated.id+" "+this.userUpdated.name);
console.log(p.id+" "+p.name);
});

this.actionType = 2;//it means update
this.modal.open();

}

onDeleteConfirm(event): void {
if (window.confirm('Are you sure you want to delete?')) {
event.confirm.resolve();
} else {
event.confirm.reject();
}
}

saveUser() {
console.log("user saveUser içi");
if (this.actionType == 1) {
this.userService.addUser(this.model)
.subscribe(res => {
console.log(JSON.stringify(res.data._body));
this.model.id = res.data._body;
this.source.prepend(this.model);
},
err => { console.log(err) });
} else if (this.actionType == 2) {
this.userService.updateUser(this.model)
.subscribe(res => {
console.log(this.model.id + '-' + this.model.name);

this.source.update(this.userUpdated, this.model);

this.userUpdated= {};
},
err => { console.log(err) });
}
this.model = {};
this.modal.close();

console.log("user saveUser dışı" + this.actionType);
this.actionType = 0;
}

}

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.