Posted in ColdFusion | Posted on 08-29-2007 | 3,169 views
My Database Explorer (first discussed here) has been updated with a few minor tweaks. First off I added a simple alpha sort to the DSNs. Secondly the IE7 issue with the SQL editor is fixed, thanks to TJ Downes. You can download the code below.


I've just installed this on my server and it does work better now in ie7. Although that fix has just set that text area size to a fixed height by the look of it. It used to resize when the div was resized in firefox but doesn't any more. Still it is better than before for ie7.
One suggestion is that if you do a select * from parks for example off the cfdocexamples and try to column sort, it's really slow. Perhaps you could change the table view to page using say max of 100 records, or have a drop down where a user can set the max.
How? Did you know Derby doesn't support TOP perhaps there is another method i'm missing for Derby.
Also, I'd like to see the hide system tables ticked by default as I think most people would rarely query them.
If you think it warrants inclusion in RIAFOrge, I'll add it. That way these suggestions can be added to a bug tracker because honestly - I don't have time now to work on it and I'll probably forget unless it is documented.
I was also thinking about hacking it so that I could give others access for select only. ie. No delete, insert or update statements.
http://cfdbexplorer.riaforge.org/
Dale found a bug that is fixed in the RIAForge version.
I am trying to generate an Excel spreadsheet from my cfgrid at the click of a button. I've added a button to the grid using EXT that onclick calls a Javascript function to generate the Excel. My problem is in that Javascript. If it were query-based I see the approach you used here. However, mine is a bound datagrid, which does not allow use of the query attribute. It is also type=html (not flash), but I don't think that matters here. So I tried to tackle it from 2 angles, but am just not smart enough. Probably something simple I'm missing. My google search returned nothing useful.
1) A bound datagrid I think returns a JSON string, so I thought about using the new cf8 function ColdFusion.JSON.decode(json), but what variable is the grid coming back with since my CFC return is "queryConvertForGrid(qread, intGridPage, intPageSize)"? I played with Firebug, but couldn't find the answer. I'm still learning to use it.
2) I thought about using the grid datasource which I already use for various EXT operations. I have the datasource defined by a global variable, but not sure how to tap the query results embedded in it. I looked at the EXT docs, no help.
Another less attractive alternative would be to regenerate the query seperately, but that is just wrong. Another would be to remove the bindings and go with a query-based approach as you did here, but that is not my preference, since it seems to be cleaner to go directly to the CFC and back, but where I'm headed if I don't get another option.
Ideas?
I'd consider looking at how the grid is bound. It is getting data from either a simple URL or a CFC, right? If so, you could simply use the button to load a CFM that gets the same data as a the grid and spits it out in the right format.
If you are concerned about sorting, then you need to examine the grid and figure out which column is currently being sorted. That is definitely possible via the API.
Your new CFM would just make use of the first CFC method.
bind="cfc:#strcomponentpath#.readdiadocumentgrid({cfgridpage}, {cfgridpagesize}, {cfgridsortcolumn}, {cfgridsortdirection}, {frmSearch:c1@none}, {frmSearch:c2@none}, {frmSearch:c3@none}, {frmSearch:c4@none}, {frmSearch:c6@none}, {frmSearch:c7@none}, {frmSearch:c8@none},...
I could send structs like:
bind="cfc:#strcomponentpath#.readdiadocumentgrid({cfgridpage}, {cfgridpagesize}, {cfgridsortcolumn}, {cfgridsortdirection}, {frmSearch:c@none}, ...
where c1 is defined in my CFM as c.c1, c2 is c.c2, etc
and then deconstructed in the CFC from the passed argument "c"?
You may be in a situation where you need to use something completely native as opposed to CF8's ajax stuff.
I think I'm close for the spreadsheet part. When the Excel button is clicked I have a JS that simplified looks like this:
function exportExcel() {
ColdFusion.Ajax.submitForm('frmSearch', 'showexcel.cfm', handleExcelResult, errorHandlerAJAX);
}
submitForm uses POST by default. showexcel.cfm invokes a CFC (using cfinvokeargument like <cfinvokeargument name="c1" value="#form.c1#" />) and correctly returns query results and using your approach to showing excel has the following:
<cfif isDefined("rstQuery.RecordCount") and rstQuery.RecordCount>
<cfsetting showdebugoutput=false>
<cfcontent type="application/msexcel" reset="true">
<cfheader name="content-disposition" value="attachment;filename=#strFilename#.xls">
<cfoutput>
<table border="1">
<tr>
<cfloop index="c" list="#rstQuery.columnlist#">
<th>#ReplaceNoCase(c,'DIA','')#</th>
</cfloop>
</tr>
<cfloop query="rstQuery">
<tr>
<cfloop index="c" list="#rstQuery.columnlist#">
<td>#rstQuery[c][currentRow]#</td>
</cfloop>
</tr>
</cfloop>
</table>
</cfoutput>
...
All works great except the spreadsheet fails to show up. Firebug showed me that the POST response is almost what I want (<table border="1"><tr><th>DOCNO</th>...) but the cfcontent is getting ignored. If I add an alert to the handleExcelResult function, it returns the html code as I saw in Firebug. For my other grid the cfcontent worked fine, but I was not doing the ColdFusion.Ajax.submitForm function. Ideas?
function handleExcelResult(sResult){
var sOption="toolbar=yes,location=no,directories=yes,menubar=yes,";
sOption+="scrollbars=yes,width=750,height=600,left=100,top=25";
var win=window.open("","",sOption);
var doc=win.document;
doc.open();
doc.write('<html><head>')
doc.write('<meta http-equiv="Content-Type" content="application/msexcel">')
doc.write('<meta http-equiv="Content-disposition": attachment;filename="SearchData.xls">')
doc.write('</head><body>')
doc.write(sResult);
doc.write('</body></html>');
doc.close();
win.focus();
}
This seems like it would be a basic need out there, but my google search failed to get me a good Javascript approach.
[Add Comment] [Subscribe to Comments]