本文档的示例代码仅适用于本文档中的示例报表/场景。若实际报表/场景与示例代码无法完全适配(如使用功能不一致,或多个宏代码冲突等),需根据实际需求开发代码。 |
有时候客户想要在仪表盘中实现,页面中只有一个参数,默认是当前月,如果查询条件设置的日期大于当前月,则用户选择的时候,将参数自动变为当前月。比如:默认当前日期为2015年09月,如果用户选择了2015年09月以前的月份,则参数值设为选择的值,并且显示相应的数据。如果用户选择了2015年09月 以后的月份,则查询参数自动变为2015年09月。
注:在参数设置中默认值需要通过SQL语句获取当前年月,比如 MySQL 的SQL语句是“select concat(left(curdate(),4),substr(curdate(),6,2)) as a from dual ”
类型 | 对象 | 事件 |
---|---|---|
ClientSide | page | onParamValueChanged |
function main(page, pageContext, param) { var dateObj = new Date(), year = dateObj.getFullYear(), month = dateObj.getMonth(), currentDate; if (month <= 8) { currentDate = year + "0" + parseInt(month + 1); } else { currentDate = year + "" + parseInt(month + 1); } if (param.value > currentDate) { page.fillParamValue(param.name, currentDate, currentDate); //给参数填值 page.commitParamValue(); //提交参数 page.refreshData(); } } |