2

I have an issue with ng2-smart-table, which I fill with an empty localdatasource.

I have a Date column, which use a custom editor :

dateInscription: {
                title: 'Date',
                filter:false,
                type: 'string',
                valuePrepareFunction: (cell, row) => {
                    return `${new Date(cell).toLocaleDateString()}`;
                },
                editor: {
                    type: 'custom',
                    component: DateRenderComponent,
                },
            }

The editor extends DefaultEditor and of course open a datepicker (p-calendar). When the user select a date, the cell value is updated using :

onSelect(event)
    {
      this.cell.newValue = this.value;
    }

The event is well fired. This work in new rows... What could be wrong ?

Once the row is created, I want to edit it, and this don't work. When I click the "save" command, the old value stay (note that other simple text columns are updated).

I can see the valuePrepareFunction beeing called after clicking "save", with the old cell value.

I've double check than the onSelect event is setting the good value in cell.newValue

Did someone already got this issue ? What was the solution ? Thanks !

Echtelion
  • 161
  • 2
  • 7
  • I'm going through this issue, and now handle the editConfirm event of the ng2-smart-table... surprise, the data is the new one ! As this work when I change others string properties, I suppose that the new Date is not committed into the datasource... WHY !! – Echtelion Mar 02 '18 at 21:00

2 Answers2

1

I got my problem solved via

html File

 <ng2-smart-table [settings]="settings" [source]="source" (editConfirm)="onEditConfirm($event)" >

Ts File

onEditConfirm(event) {
    doEdit(event.newData);

}

In your event variable, get the updated data using the "newData" as shown above

https://github.com/akveo/ng2-smart-table/blob/master/src/app/pages/examples/various/advanced-example-confirm.component.ts

Vega
  • 27,856
  • 27
  • 95
  • 103
A_H
  • 121
  • 1
  • 6
0

I did find the cause, but not an easy workaround. I reproduce the issue in commiting the value using this.source.update(old, new).

looking at the github code, update don't replace an object by another, but "fusion" the two...

And for that, it look like the localdatasource.prototype.update use an old version of deepextend (2014...) which don't manage Buffer, Regex and Date.

I will fill a bug on the ng2-smart-table github to get this fixed.

For now, you should remove the old object and add the new one, but you loose the index information... I'll complete my answer if I find something for that.

Echtelion
  • 161
  • 2
  • 7