ColdFusion:根据条件突出显示CFGrid中的行?

时间:2010-12-28 23:46:22

标签: coldfusion cfgrid

我正在Coldfusion中构建一个应用程序,基本上它是一个跟踪会员资格何时到期的模块。我正在构建所有成员的索引,我想使用cfgrid。

有没有办法在会员资格到期的x天内具体说明该行是否突出显示?

谢谢!

2 个答案:

答案 0 :(得分:1)

要做到这一点,你可能需要自己编写一些JavaScript。首先通过ColdFusion.Grid.getGridObject获取ExtJS对象,然后查看ExtJS文档(http://dev.sencha.com/deploy/dev/docs/)以查看可以执行的操作。

另一种选择是在ColdFusion中进行计算并将另一列添加到网格中。

答案 1 :(得分:0)

<cfajaximport/>
<html>

<head>
<script>

myf = function(data,cellmd,record,row,col,store) {
    // hard code a date to check against "13 Jan 2011"
    // note 0 based month index
    var today = new Date(2011,0,13);
    if(data < today) {
        //before displaying format the date
        var curr_date = data.getDate();
        var curr_month = data.getMonth();
        //javascript has month as a 0 based index so add one
        curr_month++;
        var curr_year = data.getFullYear();
        return "<span style='color:red;font-weight:bold;'>" + curr_date + "-" + curr_month + "-" + curr_year + "</span>";
    }
    else {
        //before displaying format the date
        var curr_date = data.getDate();
        var curr_month = data.getMonth();
        //javascript has month as a 0 based index so add one
        curr_month++;
        var curr_year = data.getFullYear();
        return curr_date + "-" + curr_month + "-" + curr_year;
    }
}
testgrid = function() {
    mygrid = ColdFusion.Grid.getGridObject('data');
    cm = mygrid.getColumnModel();
    // render the first column (0 based index) using the myf function above 
    cm.setRenderer(0,myf);
    mygrid.reconfigure(mygrid.getDataSource(),cm);
}
</script>
</head>

<body>

<!--- create a hard coded query for testing --->
<cfset data = queryNew("expiryDate,member")>
<cfloop from=1 to=31 index="i">
    <cfset expiryDate = createDate(2011,1,i)>
    <cfset member = "Member #i#">
    <cfset queryAddRow(data)>
    <cfset querySetCell(data, "expiryDate", expiryDate, i)>
    <cfset querySetCell(data, "member", member, i)>
</cfloop>

<cfform name="test">
<cfgrid autowidth="true" name="data" format="html" query="data" width="600">
   <cfgridcolumn name="expiryDate" header="Expiry Date">
   <cfgridcolumn name="member" header="Member">
</cfgrid>
</cfform>

<cfset ajaxOnLoad("testgrid")>
</body>
</html>