ParamQuery grid support forum

General Category => Suggest new features => Topic started by: hyh888 on May 12, 2022, 03:56:13 am

Title: Default value in colModel
Post by: hyh888 on May 12, 2022, 03:56:13 am
Now it seems that default value couldn't be set in colModel for new row of every column. Can it be added?
Then developer may get better experience in programing like following:
var colModel= [
         {title: "ID", dataIndx: "id", width: 200,dataType: "string",  editable: false },
         {title: "Country", dataIndx: "Country",width: 260, dataType: "string",default:"USA"},
         {title: "City", dataIndx: "City",width: 260, dataType: "string",default:"New York"}
                     ]
Title: Re: Default value in colModel
Post by: paramvir on May 12, 2022, 10:58:37 am
Ok noted.
Title: Re: Default value in colModel
Post by: hyh888 on June 21, 2022, 01:16:32 pm
Dear Daramvir:
If this function has been provided in new version?
Title: Re: Default value in colModel
Post by: paramvir on June 24, 2022, 04:32:04 am
Your requirement can be met by adding this code in the grid initialization object.

Code: [Select]
rowTemplate: {},
complete: function(){
var rt = this.option('rowTemplate'), cm = this.getColModel();
//debugger;
cm.forEach(function(col){
var def = col.defaultValue, di = col.dataIndx;
if( def !== undefined ){
Object.defineProperty(rt, di, {
enumerable: true,
get(){
var val = this[ "_" + di];
return val == null? def: val;;
},
set(val){
this[ "_" + di ] = val;
}
});
}
});
},

and use defaultValue instead if default since default is a reserved word.
Title: Re: Default value in colModel
Post by: hyh888 on June 28, 2022, 08:51:56 am
Dear Daramvir:
This code is too complicate, it will be better if pqgrid can add default value property in colModel.

var colModel= [
         {title: "ID", dataIndx: "id", width: 200,dataType: "string",  editable: false },
         {title: "Country", dataIndx: "Country",width: 260, dataType: "string",defaultValue:"USA"},
         {title: "City", dataIndx: "City",width: 260, dataType: "string",defaultValue:"New York"}
                     ]

Long and complicate java-like code really frustrates me, json-like concise code can really save coding time and reduce debug time.
Title: Re: Default value in colModel
Post by: paramvir on June 28, 2022, 12:30:14 pm
you don't need to work with the code. That code purpose is to add support for defaultValue property in the columns.
Title: Re: Default value in colModel
Post by: hyh888 on June 29, 2022, 08:14:51 am
Million thanks!