Displaying an Image/Icon inside an EXT.NET GridPanel Cell depinding on value - ext.net

Greeting,
I need to display an image/icon AND a value in an EXT.NET cell (of a gridpanel). The value comes from the datatable. The value can either be a string ‘good’ or ‘bad’ and resides in the column ‘Status’.
For example: good accept.png or bad cancel.png.
Layout:
<ext:GridPanel ID="grid" runat="server">
<Store>
<ext:Store ID="Store1" runat="server">
<Reader>
<ext:ArrayReader>
<Fields>
<ext:RecordField Name="status" Mapping="Status" />
</Fields>
</ext:ArrayReader>
</Reader>
</ext:Store>
</Store>
<ColumnModel ID="ColumnModel1" runat="server">
<Columns>
<ext:Column DataIndex="status" Header="Status" Width="160">
</ext:Column>
</Columns>
</ColumnModel>
</ext:GridPanel>
Now I have seen some exaples but I can’t seem to get the picture, I think it has something to do with this:
<script type="text/javascript">
function imgRenderer(value, meta, record, rowIndex, colIndex, store) {
if(data == ‘good’)
{
return "<img src='accept.png'/>"
}
else (data == "bad")
{
return "<img src='cancel.png'/>"
}
}
</script>
More info:
http://miamicoder.com/2009/displaying-an-image-inside-an-ext-js-gridpanel-cell-part-2/
http://techmix.net/blog/2010/11/25/add-button-to-extjs-gridpanel-cell-using-renderer/

I forgot to return the value.
<ext:Column ColumnID="columnStatus" DataIndex="omschrijving" Header="Status" Width="150">
<Renderer Handler="return imgRenderer(value);" />
</ext:Column>

You have options, although I think there is just one minor syntax error that is causing the problem.
Option 1:
In your existing code, you should change data to value.
Example
// existing
if(data == ‘good’)
// revised
if(value == ‘good’)
Option 2:
Rename your images to same value as the value, although this would still require using the value attribute instead of data. Rename accept.png to good.png, and same renaming with the "bad" image. With this change you shouldn't require the if|else statement.
Example
// existing
if(data == ‘good’)
{
return "<img src='accept.png'/>"
}
else (data == "bad")
{
return "<img src='cancel.png'/>"
}
// revised
return '<img src="' + value + '.png"/>';
Hope this helps.

Related

how to bind raddropdown from different sources for different rows inside rad grid?

How to bind the telerik rad containg raddropdown to bind from differrent sources in different rows.
Eg:raddropdown.dataSource=new list<string>{"apple","bat","cat"} in row 0
raddropdown.dataSource=new list<string>{"Dog","egg"}in row 1
Somebody please help.
Following is my dropdown inside a grid.
<telerik:GridTemplateColumn
HeaderText="Employees"
SortExpression="emp_name"
UniqueName="emp_name">
<ItemTemplate>
<asp:Label runat="server" ID="lblName"
Text='<%# Eval("emp_name") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<telerik:RadComboBox runat="server" ID="comboEmployees"
DataSourceID="odsEmployees"
DataTextField="emp_name"
DataValueField="emp_id">
</telerik:RadComboBox>
</EditItemTemplate>
<InsertItemTemplate>
<telerik:RadComboBox runat="server" ID="comboEmployees"
DataSourceID="odsEmployees"
DataTextField="emp_name"
DataValueField="emp_id">
</telerik:RadComboBox>
</InsertItemTemplate>
</telerik:GridTemplateColumn>
Define a ObjectDataSource as follows.
<asp:ObjectDataSource runat="server" ID="odsEmployees"
SelectMethod="getListOfEmployees"
TypeName="ABC.DEF">
</asp:ObjectDataSource>
Create a code file as follows.
namespace ABC
{
public class DEF{
public List<tbl_employees> getListOfEmployees(){
List<tbl_employees> employees = db.tbl_employees
.Where(e => e.salary > 10000)
.OrderBy(e => e.emp_name)
.ToList();
}
}
}

Create workbook with multiple sheets from Queries

I am using ColdFusion 2016 and I've discovered that the server that I'm using only has CF9, I'm pretty new to this. I've been working on updating existing code to fit what the users now want. So far I've managed, but this is beyond me. I've got a website that generates an excel workbook with one sheet. It uses HTML and a query to create it. Starts with the query name in A1 the report date in A3, the table headers in A5:H5 and then the data in A6:H53 (The exact length could vary, but always from column A - H). I'll post what is being used to create the workbook. What i want to do is use 3 more queries to add 3 more sheets to the workbook. I've tried adding a function that I found here and that didn't do any good. I tried modifying the existing code some to try and use all 4 queries, no joy.
Any help would be appreciated. Let me know if I need to add more detail.
Here's the code:(I added comments for what I added trying to get this to work)
<cfsilent>
<!--- *******************************************************************
Filename: execSummary_Excel.cfm, v1.0 03/07/2012
Created By: Original Writer
Description: Excel report export for Executive Summary Report.
Change History:
Date........Name...........Description of Change........................
08/01/2012 Original Writer Added committed column.
02/28/2013 Original Writer Added stateGM and GM.
*************************************************************************--->
<cfinvoke component="financial.financial" method="getExecSummary" returnvariable="qExecSummary">
<cfinvokeargument name="level" value="#URL.level#" />
<cfinvokeargument name="stateGM" value="#URL.stateGM#" />
<cfinvokeargument name="GM" value="#URL.GM#" />
<cfinvokeargument name="engVP" value="#URL.engVP#" />
<cfinvokeargument name="engDir" value="#URL.engDir#" />
</cfinvoke>
<!---Added this to test if I can get more than one sheet to the Workbook--->
<cfinvoke component="financial.financial" method="getExecSummary_OLD" returnvariable="qExecSummary_OLD">
<cfinvokeargument name="level" value="#URL.level#" />
<cfinvokeargument name="stateGM" value="#URL.stateGM#" />
<cfinvokeargument name="GM" value="#URL.GM#" />
<cfinvokeargument name="engVP" value="#URL.engVP#" />
<cfinvokeargument name="engDir" value="#URL.engDir#" />
</cfinvoke>
<!--- Get Report Date since qExecSummary is more complex than the other report queries --->
<cfquery name="qRpt_Date" datasource="#application.dsn#">
SELECT DISTINCT rpt_date
FROM fin_data
</cfquery>
<cfsetting requesttimeout="5000" />
</cfsilent>
<!---Added this as a function that should allow me to use multiple queries and create a workbook with more than one sheet--->
<cfscript>
//Create new workbook with one sheet
//by default that sheet is the active sheet
Workbook = SpreadsheetNew("ExecSummary");
//Add Data to the sheet
format1.bold="true";
formatNum.dataformat="0.00%";
Spreadsheetformatcell(Workbook,format1,1,1);
SpreadSheetSetCellValue(Workbook,"Executive Summary Report",1,1);
Spreadsheetformatcell(Workbook,format1,3,1);
SpreadSheetSetCellValue(Workbook,"#dateFormat(now(),'mm/dd/yyyy')#",3,1);
SpreadSheetSetCellValue(Workbook,"Data Date",5,1);
SpreadSheetSetCellValue(Workbook,"Level",5,2);
SpreadSheetSetCellValue(Workbook,"Name",5,3);
SpreadSheetSetCellValue(Workbook,"Description",5,4);
SpreadSheetSetCellValue(Workbook,"Budget",5,5);
SpreadSheetSetCellValue(Workbook,"Commited",5,6);
SpreadSheetSetCellValue(Workbook,"Spent YTD",5,7);
SpreadSheetSetCellValue(Workbook,"% Spent",5,8);
arr="Here";
writedump(arr);
//if (qExecSummary.recordCount) {
// rowNum = 6;
// arr="Here";
// writedump(rowNum);
//alert(qExecSummary.recordCount);
//for(dataRow in qExecSummary){
//SpreadSheetSetCellValue(Workbook,dateFormat(qRpt_Date.rpt_Date, 'mm/dd/yyyy'),rowNum,1);
//SpreadSheetSetCellValue(Workbook,dataRow.responsible,rowNum,2);
//SpreadSheetSetCellValue(Workbook,dataRow.name,rowNum,3);
//SpreadSheetSetCellValue(Workbook,dataRow.Description,rowNum,4);
//SpreadSheetSetCellValue(Workbook,dataRow.bud_sum,rowNum,5);
//SpreadSheetSetCellValue(Workbook,dataRow.committed,rowNum,6);
//SpreadSheetSetCellValue(Workbook,dataRow.Spent_YTD,rowNum,7);
/*if (qExecSummary.bud_sum NEQ 0){
Spreadsheetformatcell(Workbook,formatNum,rowNum,8);
//percentSpent="#(qExecSummary.Spent_YTD/qExecSummary.bud_sum)*100#";
SpreadSheetSetCellValue(Workbook,(dataRow.Spent_YTD/dataRow.bud_sum)*100,rowNum,8);
}
else {*/
//SpreadSheetSetCellValue(Workbook,0,rowNum,8);
//}
//rowNum++;
//}
//End of WriteOutput
//} else {
// SpreadSheetAddRows(Workbook,"No results for your criteria.");
//}
</cfscript>
<!---
<cffunction name="QueriesToXLS" access="public">
<cfargument name="queryArr" required="true">
<cfargument name="sheetNameArr" required="false">
<cfset tempPath="C:\Temp\ExecutiveSummary" & ".xls">
<cfset counter= 1>
<cfloop array="#ARGUMENTS.queryArr#" index="i" >
<cfset sheetName="Sheet#counter#">
<cfif isDefined("ARGUMENTS.sheetNameArr")>
<cfset sheetName=ARGUMENTS.sheetNameArr[counter]>
</cfif>
<cfspreadsheet action="update" filename="#tempPath#" query="i" sheetName="#sheetName#"/>
<cfset counter += 1>
</cfloop>
<cfreturn SpreadsheetRead(tempPath)>
</cffunction>
<cfset xlsData = QueriesToXLS([qExecSummary,qExecSummary],["ExecutiveSummary","ExecutiveSummaryOLD"])>
--->
<cfheader name="Content-Disposition" value='attachment; filename="execSummaryNew.xls"'>
<!---cfcontent type="application/msexcel" variable="#SpreadsheetReadBinary(xlsData)#" reset="true"--->
<cfcontent type="application/vnd.ms-excel"> <!---This is where the application type is being set to Excel--->
<!---html xmlns:x="urn:schemas-microsoft-com:office:excel">
<head>
</head>
<h2>Executive Summary Report</h2>
<cfoutput>
<p>#dateFormat(now(), 'mm/dd/yyyy')#</p>
</cfoutput>
<table id="tableOne" class="yui" cellspacing="0" cellpadding="5">
<thead>
<tr>
<th>Data Date</th>
<th>Level</th>
<th>Name</th>
<th>Description</th>
<th>Budget</th>
<th>Committed</th>
<th>Spent YTD</th>
<th>% Spent</th>
</tr>
</thead>
<cfif qExecSummary.recordCount>
<tbody>
<cfoutput query="qExecSummary">
<tr>
<td>#dateFormat(qRpt_Date.rpt_Date, 'mm/dd/yyyy')#</td>
<td>#qExecSummary.responsible#</td>
<td>#qExecSummary.name#</td>
<td>#qExecSummary.Description#</td>
<td>#qExecSummary.bud_sum#</td>
<td>#qExecSummary.committed#</td>
<td>#qExecSummary.Spent_YTD#</td>
<td><cfif qExecSummary.bud_sum NEQ 0>
#numberFormat((qExecSummary.Spent_YTD/qExecSummary.bud_sum)*100,"9.9")#%
<cfelse>
0
</cfif>
</td>
</tr>
</cfoutput>
</tbody>
<cfelse>
<tr>
<td colspan="9">No results for your criteria.</td>
</tr>
</cfif>
</table>
</html--->
EDIT
I have tried following the answer provided on the question referenced in the duplicate. I am not able to get it to work with the query that I have. I have added the following code in place of the script that I had:
EDIT 2
Updated this script, still not working. errors on the writeOutput().I'm not sure how to implement using a query to create the data for the rows?
<cfscript>
//Create new workbook with one sheet
//by default that sheet is the active sheet
Workbook = SpreadsheetNew("ExecSummary");
//Add Data to the sheet
format1.bold="true";
formatNum.dataformat="0.00%";
Spreadsheetformatcell(Workbook,format1,1,1);
SpreadSheetSetCellValue(Workbook,"Executive Summary Report",1,1);
Spreadsheetformatcell(Workbook,format1,3,1);
SpreadSheetSetCellValue(Workbook,"#dateFormat(now(),'mm/dd/yyyy')#",3,1);
SpreadSheetSetCellValue(Workbook,"Data Date",5,1);
SpreadSheetSetCellValue(Workbook,"Level",5,2);
SpreadSheetSetCellValue(Workbook,"Name",5,3);
SpreadSheetSetCellValue(Workbook,"Description",5,4);
SpreadSheetSetCellValue(Workbook,"Budget",5,5);
SpreadSheetSetCellValue(Workbook,"Commited",5,6);
SpreadSheetSetCellValue(Workbook,"Spent YTD",5,7);
SpreadSheetSetCellValue(Workbook,"% Spent",5,8);
if (qExecSummary.recordCount) {
rowNum = 6;
//writeOutput(query="qExecSummary");
for(dataRow in qExecSummary){
SpreadSheetSetCellValue(Workbook,dateFormat(qRpt_Date.rpt_Date, 'mm/dd/yyyy'),rowNum,1);
SpreadSheetSetCellValue(Workbook,dataRow.responsible,rowNum,2);
SpreadSheetSetCellValue(Workbook,dataRow.name,rowNum,3);
SpreadSheetSetCellValue(Workbook,dataRow.Description,rowNum,4);
SpreadSheetSetCellValue(Workbook,dataRow.bud_sum,rowNum,5);
SpreadSheetSetCellValue(Workbook,dataRow.committed,rowNum,6);
SpreadSheetSetCellValue(Workbook,dataRow.Spent_YTD,rowNum,7);
if (qExecSummary.bud_sum NEQ 0){
Spreadsheetformatcell(Workbook,formatNum,rowNum,8);
percentSpent="#(qExecSummary.Spent_YTD/qExecSummary.bud_sum)*100#";
SpreadSheetSetCellValue(Workbook,(qExecSummary.Spent_YTD/qExecSummary.bud_sum)*100,rowNum,8);
}
else {
SpreadSheetSetCellValue(Workbook,0,rowNum,8);
}
rowNum++;
}
//End of WriteOutput
} else {
SpreadSheetAddRows(Workbook,"No results for your criteria.");
}
</cfscript>
However it is showing errors on the line with the Output. I don't know what to change it to. I've searched for what is usable in the cfscript tags and found this, but there's nothing there that looks like it would help?
Made update to the <cfscript> now I'm getting this error:
FINAL EDIT
Here's the working script:
<cfsilent>
<!--- *******************************************************************
Filename: execSummary_Excel.cfm, v1.0 03/07/2012
Created By: Original Writer
Description: Excel report export for Executive Summary Report.
Change History:
Date........Name...........Description of Change........................
08/01/2012 Original Writer Added committed column.
02/28/2013 Original Writer Added stateGM and GM.
*************************************************************************--->
<cfinvoke component="financial.financial" method="getExecSummary" returnvariable="qExecSummary">
<cfinvokeargument name="level" value="#URL.level#" />
<cfinvokeargument name="stateGM" value="#URL.stateGM#" />
<cfinvokeargument name="GM" value="#URL.GM#" />
<cfinvokeargument name="engVP" value="#URL.engVP#" />
<cfinvokeargument name="engDir" value="#URL.engDir#" />
</cfinvoke>
<!---Added this to test if I can get more than one sheet to the Workbook--->
<cfinvoke component="financial.financial" method="getExecSummary331" returnvariable="qExecSummary331">
<cfinvokeargument name="level" value="#URL.level#" />
<cfinvokeargument name="stateGM" value="#URL.stateGM#" />
<cfinvokeargument name="GM" value="#URL.GM#" />
<cfinvokeargument name="engVP" value="#URL.engVP#" />
<cfinvokeargument name="engDir" value="#URL.engDir#" />
</cfinvoke>
<!--- Get Report Date since qExecSummary is more complex than the other report queries --->
<cfquery name="qRpt_Date" datasource="#application.dsn#">
SELECT DISTINCT rpt_date
FROM fin_data
</cfquery>
<cfsetting requesttimeout="5000" />
</cfsilent>
<!---Added this as a function that should allow me to use multiple queries and create a workbook with more than one sheet--->
<cfscript>
//Create new workbook with one sheet
//by default that sheet is the active sheet
Workbook = SpreadsheetNew("ExecSummary");
//Add Data to the sheet
//Formatting
format1.bold="true";
format1.fontsize=12;
format1.font="Calibri";
format2.bold="true";
format2.fontsize=18;
format2.font="Calibri";
formatNum.dataformat="0.0%";
//adding the Headers
Spreadsheetformatcell(Workbook,format2,1,1);
Spreadsheetformatcell(Workbook,format1,3,1);
Spreadsheetformatcell(Workbook,format1,5,1);
Spreadsheetformatcell(Workbook,format1,5,2);
Spreadsheetformatcell(Workbook,format1,5,3);
Spreadsheetformatcell(Workbook,format1,5,4);
Spreadsheetformatcell(Workbook,format1,5,5);
Spreadsheetformatcell(Workbook,format1,5,6);
Spreadsheetformatcell(Workbook,format1,5,7);
Spreadsheetformatcell(Workbook,format1,5,8);
SpreadSheetSetCellValue(Workbook,"Executive Summary Report",1,1);
SpreadSheetSetCellValue(Workbook,"#dateFormat(now(),'mm/dd/yyyy')#",3,1);
SpreadSheetSetCellValue(Workbook,"Data Date",5,1);
SpreadSheetSetCellValue(Workbook,"Level",5,2);
SpreadSheetSetCellValue(Workbook,"Name",5,3);
SpreadSheetSetCellValue(Workbook,"Description",5,4);
SpreadSheetSetCellValue(Workbook,"Budget",5,5);
SpreadSheetSetCellValue(Workbook,"Commited",5,6);
SpreadSheetSetCellValue(Workbook,"Spent YTD",5,7);
SpreadSheetSetCellValue(Workbook,"% Spent",5,8);
arr=server.ColdFusion.ProductVersion;
if (qExecSummary.recordCount) {
rowNum = 6;
do {
SpreadSheetSetCellValue(Workbook,dateFormat(qRpt_Date.rpt_date,'mm/dd/yyy'),rowNum,1);
SpreadSheetSetCellValue(Workbook,qExecSummary.responsible[rowNum-5],rowNum,2);
SpreadSheetSetCellValue(Workbook,qExecSummary.name[rowNum-5],rowNum,3);
SpreadSheetSetCellValue(Workbook,qExecSummary.Description[rowNum-5],rowNum,4);
SpreadSheetSetCellValue(Workbook,qExecSummary.bud_sum[rowNum-5],rowNum,5);
SpreadSheetSetCellValue(Workbook,qExecSummary.committed[rowNum-5],rowNum,6);
SpreadSheetSetCellValue(Workbook,qExecSummary.Spent_YTD[rowNum-5],rowNum,7);
if (qExecSummary.bud_sum[rowNum-5] NEQ 0){
Spreadsheetformatcell(Workbook,formatNum,rowNum,8);
SpreadSheetSetCellValue(Workbook,(qExecSummary.Spent_YTD[rowNum-5]/qExecSummary.bud_sum[rowNum-5]),rowNum,8);
}
else {
SpreadSheetSetCellValue(Workbook,0,rowNum,8);
}
rowNum++;
} while (rowNum - 6 LT qExecSummary.recordCount);
} else {
SpreadSheetAddRows(Workbook,"No results for your criteria.");
}
SpreadsheetCreateSheet(Workbook,"ExecSummaryTest");
SpreadsheetSetActiveSheet(Workbook,"ExecSummaryTest");
//Formatting
format1.bold="true";
format1.fontsize=12;
format1.font="Calibri";
format2.bold="true";
format2.fontsize=18;
format2.font="Calibri";
formatNum.dataformat="0.0%";
Spreadsheetformatcell(Workbook,format2,1,1);
Spreadsheetformatcell(Workbook,format1,3,1);
Spreadsheetformatcell(Workbook,format1,5,1);
Spreadsheetformatcell(Workbook,format1,5,2);
Spreadsheetformatcell(Workbook,format1,5,3);
Spreadsheetformatcell(Workbook,format1,5,4);
Spreadsheetformatcell(Workbook,format1,5,5);
Spreadsheetformatcell(Workbook,format1,5,6);
Spreadsheetformatcell(Workbook,format1,5,7);
Spreadsheetformatcell(Workbook,format1,5,8);
SpreadSheetSetCellValue(Workbook,"Executive Summary Report",1,1);
SpreadSheetSetCellValue(Workbook,"#dateFormat(now(),'mm/dd/yyyy')#",3,1);
SpreadSheetSetCellValue(Workbook,"Data Date",5,1);
SpreadSheetSetCellValue(Workbook,"Level",5,2);
SpreadSheetSetCellValue(Workbook,"Name",5,3);
SpreadSheetSetCellValue(Workbook,"Description",5,4);
SpreadSheetSetCellValue(Workbook,"Budget",5,5);
SpreadSheetSetCellValue(Workbook,"Commited",5,6);
SpreadSheetSetCellValue(Workbook,"Spent YTD",5,7);
SpreadSheetSetCellValue(Workbook,"% Spent",5,8);
arr=server.ColdFusion.ProductVersion;
if (qExecSummary331.recordCount) {
rowNum = 6;
do {
SpreadSheetSetCellValue(Workbook,dateFormat(qRpt_Date.rpt_date,'mm/dd/yyy'),rowNum,1);
SpreadSheetSetCellValue(Workbook,qExecSummary331.responsible[rowNum-5],rowNum,2);
SpreadSheetSetCellValue(Workbook,qExecSummary331.name[rowNum-5],rowNum,3);
SpreadSheetSetCellValue(Workbook,qExecSummary331.Description[rowNum-5],rowNum,4);
SpreadSheetSetCellValue(Workbook,qExecSummary331.bud_sum[rowNum-5],rowNum,5);
SpreadSheetSetCellValue(Workbook,qExecSummary331.committed[rowNum-5],rowNum,6);
SpreadSheetSetCellValue(Workbook,qExecSummary331.Spent_YTD[rowNum-5],rowNum,7);
if (qExecSummary331.bud_sum[rowNum-5] NEQ 0){
Spreadsheetformatcell(Workbook,formatNum,rowNum,8);
SpreadSheetSetCellValue(Workbook,(qExecSummary331.Spent_YTD[rowNum-5]/qExecSummary331.bud_sum[rowNum-5]),rowNum,8);
}
else {
SpreadSheetSetCellValue(Workbook,0,rowNum,8);
}
rowNum++;
} while (rowNum - 6 LT qExecSummary331.recordCount);
} else {
SpreadSheetAddRows(Workbook,"No results for your criteria.");
}
SpreadsheetSetActiveSheet(Workbook,"ExecSummary");
</cfscript>
<cfheader name="Content-Disposition" value='attachment; filename="execSummaryNew.xls"'>
<cfcontent type="application/msexcel" variable="#SpreadsheetReadBinary(Workbook)#" reset="true">
WriteOutput() is for displaying data on screen. To add data to a spreadsheet, you need to use spreadsheet functions. In your scenario, you can use a for/in loop to iterate through the query rows. Then use SpreadSheetSetCellValue(sheet, value, row, col) to populate the individual cells.
Update 1:
If you run the code below (from "Edit 2"), in a brand new .cfm script, you will see it works perfectly. So any errors must be coming from a different part of the code. If you are having trouble tracking down errors, I would recommend starting over with a clean slate. Create a brand new script with very simple code: just the minimum necessary to generate the spreadsheet. Omit anything extra like functions, downloads, etcetera and get the basic code working first.
<cfscript>
// FOR DEMO ONLY: Create manual queries
qRpt_Date = queryNew("");
queryAddColumn(qRpt_Date, "Rpt_Date", [now()]);
qExecSummary = queryNew("");
queryAddColumn(qExecSummary, "responsible", [1,12,13]);
queryAddColumn(qExecSummary, "bud_sum", [0,50,100]);
queryAddColumn(qExecSummary, "Spent_YTD", [0,50,100]);
queryAddColumn(qExecSummary, "Name", ["Name A","Name B","Name C"]);
queryAddColumn(qExecSummary, "Description", ["Description A","DescriptionB","Description C"]);
queryAddColumn(qExecSummary, "Committed", [0,50,100]);
//Create new workbook with one sheet
//by default that sheet is the active sheet
Workbook = SpreadsheetNew("ExecSummary");
//Add Headers
headerTextFormat.bold=true;
Spreadsheetformatcell(Workbook,headerTextFormat,1,1);
SpreadSheetSetCellValue(Workbook,"Executive Summary Report",1,1);
Spreadsheetformatcell(Workbook,headerTextFormat,3,1);
SpreadSheetSetCellValue(Workbook, dateFormat(now(),'mm/dd/yyyy'),3,1);
SpreadSheetSetCellValue(Workbook,"Data Date",5,1);
SpreadSheetSetCellValue(Workbook,"Level",5,2);
SpreadSheetSetCellValue(Workbook,"Name",5,3);
SpreadSheetSetCellValue(Workbook,"Description",5,4);
SpreadSheetSetCellValue(Workbook,"Budget",5,5);
SpreadSheetSetCellValue(Workbook,"Commited",5,6);
SpreadSheetSetCellValue(Workbook,"Spent YTD",5,7);
SpreadSheetSetCellValue(Workbook,"% Spent",5,8);
//Add data detail
if (qExecSummary.recordCount) {
// Start populating the spreadsheet on this row number
// Change as needed.
rowNum = 6;
// Loop through query rows
for(dataRow in qExecSummary) {
// add
SpreadSheetSetCellValue(Workbook,dateFormat(qRpt_Date.rpt_Date, 'mm/dd/yyyy'),rowNum,1);
SpreadSheetSetCellValue(Workbook,dataRow.responsible,rowNum,2);
SpreadSheetSetCellValue(Workbook,dataRow.name,rowNum,3);
SpreadSheetSetCellValue(Workbook,dataRow.Description,rowNum,4);
SpreadSheetSetCellValue(Workbook,dataRow.bud_sum,rowNum,5);
SpreadSheetSetCellValue(Workbook,dataRow.committed,rowNum,6);
SpreadSheetSetCellValue(Workbook,dataRow.Spent_YTD,rowNum,7);
if (qExecSummary.bud_sum != 0){
Spreadsheetformatcell(Workbook,formatNum,rowNum,8);
SpreadSheetSetCellValue(Workbook,(qExecSummary.Spent_YTD/qExecSummary.bud_sum)*100,rowNum,8);
}
else {
SpreadSheetSetCellValue(Workbook,0,rowNum,8);
}
rowNum++;
}
//End of WriteOutput
} else {
SpreadSheetAddRows(Workbook,"No results for your criteria.");
}
//For test purposes, save the results to a file
SpreadSheetWrite(Workbook, "c:/path/to/yourFile.xls", true);
WriteOutput("Done!");
</cfscript>
Update 2:
As noted in the comments, for..in query loops are not supported in CF9. If you are using an older version of CF, then you will need to use a from/to loop instead.
// Loop through query rows
for(x = 1; x lte yourQueryName.recordCount; x++) {
SpreadSheetSetCellValue(Workbook, yourQueryName.YourColumnName[x], theSheetRowNum, 1);
// ...
theSheetRowNum++;
}
Side note, personally I prefer cfscript. However, if you feel more comfortable with CFML you can always rewrite the example. Just get rid of the cfscript tags and replace:
<cfscript>
SomeFunctionName(....);
</cfscript>
with:
<cfset SomeFunctionName(....)>

LifeRay creating a new type of aui validator

I want to create a new type of aui validator.
For example :
<aui:input name="firstName" type="text" maxlength="40">
<aui:validator name="required" />
<aui:validator name="alpha" />
</aui:input>
the alpha validator does not accept the space character, i want to use a type that accepts alpha characters plus the space character, i have already a solution using javascript to use a custom validator, but i want to define a new validator type to use like the others by invoking the validator tag e.g :
<aui:validator name="myValidator" />
Is that possible ?! and how can i do it ;)
Try your luck on it :)
<aui:input name="firstName" type="text">
<aui:validator name="myValidator" errorMessage="numbers-not-allowed">
function(val, fieldNode, ruleValue){
var matches = val.match(/\d+/g);
if(matches != null)
return false;
else
return true;
}
</aui:validator>
</aui:input>
As an alternative to Parkash answer, you can make a separate jspf file and write your validations like this:
<aui:script use="liferay-form">
var ns = '<portlet:namespace/>';
window.onload = function() {
var form = Liferay.Form.get(ns+'form_add_user');
form.set(
'fieldRules',
[
{
fieldName: ns+'middlename',
validatorName: 'custom_middlename',
custom: true,
errorMessage: 'Only text and spaces here!',
body: function(value, field, rule)
{
return /^[a-zA-Z\s\.\u00E0-\u00FC]+$/.test(value);
}
},
...
]
);
}
</aui:script>
Found in Liferay 7.0 documentation

How to disable special characters and alphabets in Primefaces input text?

I want a <p:inputText> which should only accept numbers and not any other characters. Is it possible so that the user can only type in numbers and the other characters are disabled? If so, please let me know how.
In the end, the <h:inputText> and <p:inputText> components will render an <input type="text" /> HTML component. The only thing you need is to apply a JavaScript method to restrict the characters that will be allowed in the text.
Knowing this, you can use any of the methods provided in the question HTML Text Input allow only Numeric input. I'll show you an example based on the second answer of the post:
<h:head>
<script type="text/javascript">
//<![CDATA[
var numericRegex = /\d+\.?\d*/;
function validateNumericInput(evt, text) {
var theEvent = evt || window.event;
var key = theEvent.keyCode || theEvent.which;
key = String.fromCharCode( key );
if (key === '.') {
theEvent.returnValue = (text.indexOf(key) < 0);
} else {
var regex = /\d/;
if( !regex.test(key) ) {
theEvent.returnValue = false;
if(theEvent.preventDefault) theEvent.preventDefault();
}
}
}
//]]>
</script>
</h:head>
<h:body>
Try to write a non-numeric
<p:inputText onkeypress="validateNumericInput(event, this.text)" />
</h:body>
Note that this example only allows to write positive real numbers, just change the JavaScript method to define a different behavior.

Custom Forms Styling

New to orchard. I'm trying to style a custom form without success. I've also been using the shape modeler.
I created a New ContentType and add Fields f1, f2, f3... I create a CustomForm. Now I want to wrap different divs around certain fields say
<div class="g1">
f1
f2
</div>
<div class="g2">
f4
f6
</div>
BTW I've tried this construct without success:
dynamic content = #Model.Content;
<div class="g1">
if(#content.ContentTypeName.f1 || #content.ContentTypeName.f2)
{ #Dispaly(...)
}
</div>
Can this be done in the content.edit.cshtml view?
If so please provide an example.
Thanks
Also, is there any way to reflect the properties of Model.Content during runtime?
What I did was create local zones in the Content_Edit alternate then rearrange the fields using placement.info
Placement.info:
<Match ContentType="MyForm">
<Place Fields_Input_Edit-FirstField="MyFirstZone:1"/>
<Place Fields_Input_Edit-SecondField="MySecondZone:1"/>
</Match>
Content.Edit-MyForm.cshtml:
<div class="edit-item">
<div class="edit-item-primary">
#if (Model.Content != null)
{
<div class="edit-item-content">
<div class="first-zone">
#Display(Model.MyFirstZone)
</div>
<div class="second-zone">
#Display(Model.MySecondZone)
</div>
</div>
}
</div>
....
</div>
Typically in Orchard, you override templates for parts and fields, not for the whole content item. Shape tracing can help you determine what template alternates you can use for each field and even generate the file with the default code for you to modify.
Also, Model.Content, if anything, will be a zone, not the content item. Depending on which template you're in, you may be able to use Model.ContentItem instead.
Finally came up with a solution, albeit quite ugly, but it works:
In my alternate associated with the Content_Edit:
#{
dynamic content = Model.Content;
}
<div class="g1">
#{
foreach (var item in content)
{
if (item.Model.GetType().Name == "BooleanField")
{
if (f.Name == "f1" || f.Name == "f2")
{
#Display(item);
}
}
}
}
</div>
<div class="g2">
#{
foreach (var item in content)
{
if (item.Model.GetType().Name == "BooleanField")
{
if (f.Name == "f4" || f.Name == "f6")
{
#Display(item);
}
}
}
}
</div>

Resources