akveo / akveo/ng2-smart-table

having some problems with the crud of ng2-smart-table

Aperta
#1,282 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
TypeScript
Stelle
1.6k
Fork
867
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

i have the table already mentioned, and i have created components to be consumed from outside, the problem is, i had the table in mode: inline and when i try to update some data, the data disappears from the table, and i have to re write it again or in other case if the data comes from the server (JSON) it happens the same. So i changed the table to mode: external now the problem is, i dont know how to make the methods Create/save/edit/cancel (create: for creating a new row in the table) work, i have tried to look for some answers in google and on github too, and nothing concrete for all those methods, anyway, here it goes my code.

i have created the settings on an external service, and call it from the component

hope u guys can help me with this...

**mapeo-component.ts**

```
import {​​​​​​​​ Component, EventEmitter, OnInit }​​​​​​​​ from'@angular/core';
import {​​​​​​​​ LocalDataSource }​​​​​​​​ from'ng2-smart-table';
import {​​​​​​​​ MapeoService }​​​​​​​​ from'src/app/services/mapeos/mapeos.service';
import {​​​​​​​​ MapeoSettingsService }​​​​​​​​ from'../../../services/mapeos/mapeo-settings.service';

@Component({​​​​​​​​
selector:'app-mapeo',
templateUrl:'./mapeo.component.html',
styleUrls: ['./mapeo.component.scss']
}​​​​​​​​)
exportclassMapeoComponentimplementsOnInit {​​​​​​​​

publicsettings = this.mapeoSetting.settings;
publicdataTable: LocalDataSource;

constructor(privatemapeoSetting: MapeoSettingsService, privatemapeoService: MapeoService) {​​​​​​​​ }​​​​​​​​

ngOnInit(): void {​​​​​​​​
this.dataTable = newLocalDataSource();
this.getDataTable();
}​​​​​​​​

getDataTable() {​​​​​​​​
this.mapeoService.getDataTable()
.subscribe((resp) => {​​​​​​​​
this.dataTable.load(resp);
}​​​​​​​​);
}​​​​​​​​

onCreate(event) {​​​​​​​​
//
}​​​​​​​​

onAdd(event) {​​​​​​​​
//
}​​​​​​​​

onEdit(event) {​​​​​​​​
this.dataTable.update();
}​​​​​ ​ ​ ​

onDelete(event) {​​​​​​​​
this.dataTable.remove(event.data);
}​​​​​​​ ​
}​​​​​​​​

```
**mapeo-component.html**

```





Premium Business


Premium Economy


Economy







```

**mapeo-settings.service.ts**

```
import { Injectable } from '@angular/core';
import { EconomyComponent } from 'src/app/components/home/mapeo/custom-components/economy/economy.component';
import { PremiumBusinessComponent } from 'src/app/components/home/mapeo/custom-components/premium-business/premium-business.component';
import { PremiumEconomyComponent } from 'src/app/components/home/mapeo/custom-components/premium-economy/premium-economy.component';

@Injectable({
providedIn: 'root'
})
export class MapeoSettingsService {

constructor() { }

settings = {
hideHeader: false,
columns: {
carrier: {
title: 'Carrier',
placeholder: 'Carrier',
editor: {
type: 'list',
config: {
list: [
{ value: undefined, title: 'Carrier' },
{ value: 'SCL', title: 'SCL' },
{ value: 'MIA', title: 'MIA' }
]
}
}
},
pais: {
title: 'País',
},
od: {
title: 'OD',
},
j: {
title: 'J',
filter: false,
valuePrepareFunction: (cell, row) => {
if (row.j === undefined) { return row.premiumBusiness.j; }
return row.j;
},
type: 'html',
editor: {
type: 'custom',
component: PremiumBusinessComponent,
}
},
c: {
title: 'C',
filter: false,
valuePrepareFunction: (cell, row) => {
if (row.c === undefined) { return row.premiumBusiness.c; }
return row.c;
},
type: 'html',
editor: {
type: 'custom',
component: PremiumBusinessComponent,
}
},
usuario: {
title: 'Usuario',
},
fecha: {
title: 'Fecha',
filter: false
},
},
pager : {
display: true,
perPage: 8
},
filter: {
inputClass: 'size-filter'
},
actions: {
position: 'right',
columnTitle: 'Acciones'
},
add: {
confirmCreate: true,
addButtonContent: `
+
Nuevo
`,
createButtonContent: ``,
cancelButtonContent: ``
},
edit: {
confirmSave: true,
editButtonContent: ``,
saveButtonContent: ``,
cancelButtonContent: ``
},
delete: {
confirmDelete: true,
deleteButtonContent: ``,
},
attr: {
class: 'table table-bordered'
},
mode: 'external'
};
}
```

**mapeo.json**

```
[
{
"carrier": "CL",
"pais": "Chile",
"od": "Todos",
"usuario": "Diego",
"fecha": "10-10-2021",
"premiumBusiness": {
"j": "J",
"c": "C",
}
}
]
```

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.