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

defaultValue columns property not supported #137

Closed
nssoft-rlagrange opened this issue Sep 13, 2023 · 4 comments
Closed

defaultValue columns property not supported #137

nssoft-rlagrange opened this issue Sep 13, 2023 · 4 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@nssoft-rlagrange
Copy link

Hi,

In the initial ng2-smart-table, we had a defaultValue property on column settings, in order to bring a value when the add button is clicked.
It's missing in your implementation.
Is it possible to bring it back ? An alternative would be a handler to provide a new object when the add button is clicked ?

Regards,

@uap-universe
Copy link
Collaborator

Unfortunately there is no defaultValue property in the official documentation of the original ng2-smart-table. But I have looked into the code and I think I understand what this hidden feature did. It shouldn't be too complicated to add it in the next version.

@uap-universe uap-universe added the ng2-smart-table-migration An issue that arised when migrating from the original ng2-smart-table to this fork. label Sep 29, 2023
@uap-universe uap-universe added this to the 3.1.0 milestone Sep 29, 2023
@uap-universe uap-universe self-assigned this Oct 23, 2023
@uap-universe
Copy link
Collaborator

uap-universe commented Oct 23, 2023

Hello @nssoft-rlagrange

please have a look at these two comments:

// TODO: fix that the "new row" is always created, even when the table is not even configured to add new rows
this.createNewRow();

createNewRow() {
// TODO: the empty object is invalid data in general and is very likely breaking almost every other function
// in particular, custom valuePrepareFunction can explode (see the related hack in the Cell's constructor)
// we should some day fix this by defining a valueCreateFunction that can create a reasonable default object
this.newRow = new Row(-1, {}, this);
this.newRow.isInEditing = true;
}

Having a defaultValue setting in IColumn would still leave the other attributes of the object undefined.

So I would like to implement the idea from the comment, to have a valueCreateFunction globally in the table settings, that is supposed to create an entirely valid object. The default values could be specified there.

Would that also solve your problem?

@nssoft-rlagrange
Copy link
Author

That look like how I solved this in my code :

settings.ts:24 : interface Settings {... , newData?:any } // provide a default data for any row creation
grid.ts:80 : this.dataSet = new DataSet([], this.settings.columns, this.settings.newData ?? {}); // settings sent to dataset
data-set.ts:8: newData:any; // new private property after newRow
data-set.ts:16: constructor(data: Array = [], protected columnSettings: IColumns, newData?:any) // add newData to ctor
data-set.ts:20 : this.newData = newData; // in ctor, set new property
data-set.ts:178: this.newRow = new Row(-1, Object.assign({}, this.newData), this); //duplicate the new data and set it to new row
row.ts:40 : (replace first line with theses two) :
var copiedNewData = Object.assign({},this._dataSet.newData); // clone "newData" object to cut any object references to original data
const values = Object.assign(copiedNewData, this.data); //set to new row

Sorry again for not being able to provide a formal github pull request.

@uap-universe
Copy link
Collaborator

It's alright. I will implement it for version 3.1.0.

@uap-universe uap-universe added enhancement New feature or request and removed ng2-smart-table-migration An issue that arised when migrating from the original ng2-smart-table to this fork. labels Oct 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants