Dear Isomorphics!
When I need to have a ListGrid column with a numerical calculation, I use the Add Formula Column... option on the ListGrid context menu; then, I use arithmetic operations and the mathematical functions that SmartGWT has predefined (min, max, round, ceil, etc.).
I recently had the need to include calculations between dates within those formula fields. Unfortunately, I did not find posts related to this functionality; I only found that the dateAdd() function can be used, but I cannot include Date type fields in it, since they are not available in the column selector.
However, in order to illustrate what I need, I managed to recreate it by modifying this example, where I create a couple of Date fields and create a calculated field with the formula that returns the difference between those two Date fields. Below is the script I used for replacing the .js file script — which, by the way, only worked on the SmartGWT 11 demo —
I would like to know if there is any approach so that Date fields can be included in the field selector of the formula editor, and thus obtain, for example, the number of days between two dates.
Thanks in advance for your support!
Best regards,
Oscar Londoņo
When I need to have a ListGrid column with a numerical calculation, I use the Add Formula Column... option on the ListGrid context menu; then, I use arithmetic operations and the mathematical functions that SmartGWT has predefined (min, max, round, ceil, etc.).
I recently had the need to include calculations between dates within those formula fields. Unfortunately, I did not find posts related to this functionality; I only found that the dateAdd() function can be used, but I cannot include Date type fields in it, since they are not available in the column selector.
However, in order to illustrate what I need, I managed to recreate it by modifying this example, where I create a couple of Date fields and create a calculated field with the formula that returns the difference between those two Date fields. Below is the script I used for replacing the .js file script — which, by the way, only worked on the SmartGWT 11 demo —
Code:
isc.DynamicForm.create({ ID:"order", width:500, fields: [ { type:"header", defaultValue:"Subtract two dates" }, { name:"shipDays", title:"Day to subtract", type:"integer", defaultValue: 15, visible:false }, { name:"iniDate", title:"First Date", type:"date", canEdit:true, formula: { text: "DateAdd( new Date(), 'd', -shipDays)" } }, { name:"endDate", title:"Last Date", type:"date", canEdit:true, formula: { text: "new Date()" } }, { name:"dife2Dates", title:"Difference", type:"integer", canEdit:false, formula: { text: "round((endDate - iniDate) / (1000 * 3600 * 24), 0)" } } ] });
Thanks in advance for your support!
Best regards,
Oscar Londoņo
Comment