CFGRID vertical scrollbar and restricted visible records - coldfusion

I am working on coldfusion 10 and i have the following requirement,
How I need to display 100 records in first page with 18 records visible and remaining 82 records visible should be through scroll bar.
Your help is greatly appreciated.
Thank you in advance.

This sounds like an encapsulation thing. You provided no code in your question so I am going to do the best here conceptually.
You will have a query that selects 100 records using <cfquery>
I am not sure your SQL base so you can limit it with <cfquery> and the maxrows parameter like this:
<cfquery name="q"
datasource="#application.dsn#"
maxrows="100">
SELECT * FROM events order by someDate Desc
</cfquery>
or you can use TOP or LIMIT in SQL itself.
Next comes your table.
To keep concepts simple I broke it up into a div and you can adapt it to your table or grid or whatever:
<cfoutput query="q" maxrows="18">
<div>#firstcolumn# - #secondColumn# - etc.</div>
</cfoutput>
The rest spill into a scrollable div.
<div style="width:500px;height:100px;overflow:auto;">
<cfoutput query="q" startrow="19">
#firstcolumn# - #secondColumn# - etc.
</cfoutput>
</div>
So then the main concepts of concern are:
Your SQL query limited and ordered.
Your first div (or table row or grid row) with MAXROWS set to 18
Your scrolling div (or whatever) with STARTROWS set to 19
The rest falls into place.

Related

Hiding (not eliminating) duplicates in ColdFusion array

We have a three-panel display in which Panel One shows a list of countries, Panel Two shows a list of organizations, and Panel Three shows a list of aircraft. If you click a country, both the organizations and aircraft are filtered by that country, using IDs for each.
This is all working fine, but the list of aircraft comes from a "linking table" -- each record contains aircraft ID and name, and operator ID and name. Any given type of aircraft can be listed multiple times, depending on how many organizations operate it. For example, "AW159 Wildcat" is listed twice, once for Army Air Corps and once for Royal Navy. The way it works right now, "AW159" is listed in Panel Three twice when the page initially loads.
I would like any given aircraft to be displayed only once on initial page load, regardless of how many times it may be listed in this linking table. But, I want all the "duplicates" available to be shown, if somebody filters on the operating organization.
Is there a way to loop over all the aircraft but somehow hide duplicates of aircraft ID? Or, might there be a larger problem with the way our database is designed? I am open to suggestions. Thank you all very much in advance!
EDIT: sorry for not posting code; here is some. Thanks everybody for all of your help!
1. Query and array population in cfc:
<cfquery name="queryByOperator" datasource="vertipedia">
SELECT view_aircraftbyoperators.aircraftID
, view_aircraftbyoperators.Aircraft
, view_aircraftbyoperators.operatorID
, view_aircraftbyoperators.Operator
, tbl_companies.country
, tbl_companies.companyShortName
FROM view_aircraftbyoperators JOIN tbl_companies
ON tbl_companies.ID = view_aircraftbyoperators.operatorID
ORDER BY Aircraft
</cfquery>
<cfset count = 1>
<cfset aircraftByOperator = arrayNew(2)>
<cfloop query="queryByOperator">
<cfset aircraftByOperator[count][1] = aircraftID>
<cfset aircraftByOperator[count][2] = Aircraft>
<cfset aircraftByOperator[count][3] = operatorID>
<cfset aircraftByOperator[count][4] = Operator>
<cfset aircraftByOperator[count][5] = country>
<cfset count = count+1>
</cfloop>
2. Outputting on page:
<ul>
<cfloop from="1" to="#ArrayLen(aircraftByOperator)#" index="i">
<cfoutput>
<li name="#aircraftByOperator[i][3]#" class="#aircraftByOperator[i][5]#">
<p>
#aircraftByOperator[i][2]#
</p>
</li>
</cfoutput>
</cfloop>
</ul>
[i][1], [i][3] and [i][5] are all IDs. "operatorID" is the one that will change depending on who operates the aircraft. I hope this helps explain what I am trying, and again, many thanks!
Dan Bracuk's comment "Does this mean you are pre-loading all your data into javascript? It might be more efficient to throw some ajax in there and just get what you need when you need it" ended up being the way to go for us. I would like to mark his comment as the answer, but am unable to see how to do that.
For others who may read this post, we
Loaded all of the aircraft initially
When a visitor filters by country and/or organization, a new query is sent via ajax
I was having a hard time formatting the returned data, so I used jQuery's load() to format it and drop it in the proper place in the output panel.
As Dan said, it is very fast and much easier to work with, especially as our database continues to grow.
Thanks Dan!

Coldfusion query of queries with row numbers passed to second query

I'm doing the following query of queries. The first dump of the query shows the entire excel sheet, the second dump shows the results of the second query.
I'm doing a validation check of the excel sheet to make sure there are no more pit bulls breeds brought into the system and I need to be able to tell the user which row on the excel sheet has the pit-bull.
How do I get the row numbers from the first row to appear in the second row? So the user can make changes on the excel sheet.
Do I have to resort to editing the excel document when it was first uploaded into the server and add a row number column to it? There is probably a better way to accomplish this.
<cffunction name="validateExcelSheet" access="public" output="yes" returnType="void"
hint="check dogs">
<cfspreadsheet
action="read"
src="#SESSION.theFile#"
headerrow= "1"
excludeHeaderRow = "true"
query = "allData"
rows = "1-#lastRow#" />
<cfscript>
pitBullcheck = new Query(
sql ="SELECT * FROM allData where breed like 'Pit%' ",
dbtype = "query",
allData = allData);
pitBullresult = pitBullcheck.execute().getResult();
</cfscript>
</cffunction>
Here's a tag based version of cfquery
<cfquery name="pitBullresult" dbtype="query">
SELECT *
FROM allData
WHERE breed LIKE 'Pit'
</cfquery>
That is not something you can do with cfspreadsheet. CFSpreadsheet only returns the cell values. It does not provide the physical row numbers, within the spreadsheet, that contained those values.
Also, something else to keep in mind is that CFSpreadsheet only returns "logical" (ie populated) rows/cells. That is not the same as the "physical" row numbers 1,2,3,... and column headers A,B.C.... that you see in Excel. Since users can enter values anywhere within a spreadsheet, logical and physical are not always the same thing.
For example, create a blank spreadsheet. Then enter values in cells
A2 and A25. Now run your code above. While you might expect the
resulting query to contain twenty-five (25) records, it will only
contain two (2), because only two cells were populated.
query
Row | COL_1
1 | Value in cell A2 (physical row 2)
2 | Value in cell 25 (physical row 25)
I think best you could do with cfspreadsheet is to loop through the query and display the relative row number within the results ie query.currentRow. If the populated data always starts within the first few rows, that might be good enough for your purposes. If not, it could get a bit confusing ...
That said, technically you could get the real physical row numbers. However, it requires much lower level code, which quite honestly ... seems like a lot of work, for very little gain.

cfml and resorting part of a query

Just wondering, given a query and output like so:
<cfoutput query="someItems" group="someColumnName">
... doing some stuff here ..
<cfoutput> doing stuff with some sub items </cfoutput>
</cfoutput>
if there's a way to change the order of elements in the 'inner' cfoutput ?
Can the query be both grouped and sorted by?
You will need to add ORDER BY clauses in your query for this to work, but you can nest cfoutput tags that use the group attribute.
<cfoutput query="someItems" group="someColumnName">
... doing some stuff here ..
<cfoutput group="someOtherColumnName> doing stuff with some sub items </cfoutput>
</cfoutput>
This assumes that in your query you have something that looks like:
ORDER BY someColumnName, someOtherColumnName
Keep in mind that the group attribute of cfquery is not the same as the GROUP BY clause in a SQL statement. You can use the group attribute of cfoutput for ANY column that is in the ORDER BY clause in your query.
One solution is to restructure your code to use the query-of-queries approach. Here is a good example of doing so:
http://www.bennadel.com/blog/2211-ColdFusion-Query-Of-Queries-vs-The-Group-Attribute-In-CFOutput.htm
Basically, you pull out all the data you care about in one master query (probably the query you have already written). You add a second query (against your first query, not against the database) that does the group by and aggregation of data that you need at the top level loop. Inside the loop driven by your second query, you use the row data in the group as a parameter to yet another query (against your first query again, not against the database) to pull out all the data relating to the current row ordered however you desire.
This idea of querying your query seems odd at first, but I have not had performance problems with it and it gives you a lot of flexibility to do what you want in your inner loop. Good luck!

CFDump of query column does not display all values

The dumping results for the following QoQ are perfectly fine:
<cfquery datasource = "XX.XX.X.XX" name="master2">
SELECT DATE(Timedetail) as FIRSTCONN
, count(Timedetail) as FIRSTOccurances
, EVENTS
FROM MyDatabase
WHERE EVENTS = "FIRST" GROUP BY FIRSTCONN
<!--- LIMIT 0,10 --->;
</cfquery>
<cfdump var="#master2#">
<cfquery dbtype="query" name="detail2">
SELECT *
FROM master2
WHERE FIRSTCONN >= <cfqueryparam value="#startdate#" cfsqltype="cf_sql_date">
AND FIRSTCONN < <cfqueryparam value="#enddate#" cfsqltype="cf_sql_date">;
</cfquery>
Dumping Result: <cfdump var="#detail2#"><cfabort>
However, when I try to use the following check on the QoQ:
Dumping Result: <cfdump var="#detail2.FIRSTCONN#"><cfabort>
I don't see the full list of FIRSTCONN values. Instead I just see one line:
Dumping Result: {ts '2013-06-29 00:00:00'}
Ideally I should see the list of all the FIRSTCONN in my browser, shouldn't I?
You are looking at the default behaviour of coldfusion. When you output or dump queryname.fieldname, and don't specify a row number, you get the value from the first row. If you want to see all the rows, your choices are:
Look at the value list
Output/dump the entire query
Do another q of q for just that column and cfdump it.
Use cfoutput with a query attribute and just output that field
If you are looking to produce the same structured output that cfdump produces when dumping a query, I have two suggestions:
My First Inclination:
<cfdump var="#ListToArray(ValueList(queryName.columnName))#" />
That one is obviously a, very, minor continuation on Dan's suggestion.
The second is available for CF 8+ and it is
Exactly What You Wanted:
<cfdump var="#queryName#" show="columnName"/>
You may specify either columns to display in the output via the show attributes or you can hide specific columns by assigning a value to the hide attribute.
CFAbort in CF Docs
Granted, this post is almost 18 months old but maybe this will help someone that stumbles onto this page.
This is a little off topic, but I'd like to point out that in my instance of CF2016 the cfdump function suppresses the output of columns (and makes them appear empty) that have lots of text in them (or have the option to have lots of text). I'm not sure if it's the nVarChar(max) setting of the table field or what, but in order to see the content of these big fields, I actually have to make a separate query that selects only this one field, and use a separate cfdump in order to see its contents. This is only for debugging purposes, but it will keep you from going crazy and rewriting your update and insert statements over and over (because they appear to not be working all the way)...

Handling CFSELECT

I'm totally unused to Cold Fusion, I'd like to know how to handle a multiple CFSELECT, in particular how to know how many rows I've selected and taking them one by one.
Actually I've managed to see all the rows togheter:
<!--- page_a.cfm --->
<cfform name="fooform" ........>
<cfselect query="myquery" name="fornitori" multiple="yes"></cfselect>
<!--- page_b.cfm --->
<cfoutput>#form.fornitori#</cfoutput>
And, if it's not too much, I'd like to know why it's not correct to write:
<!--- page_b.cfm --->
<cfoutput>#fooform.fornitori#</cfoutput>
Since it is a multiple selection list, the options you select will be submitted to page_b.cfm as a comma delimited list. This means you can use list functions to calculate the total items selected and cfloop to iterate through the selections individually. Note, when using "multiple" select lists, if you select nothing the form field will not exist.
<cfparam name="form.fornitori" default="">
<cfoutput>
Total Items Selected = <cfoutput>#listLen(form.fornitori)#</cfoutput>
Individual Selections:<br>
<cfloop list="#form.fornitori#" index="theSelection">
#theSelection#<br>
</cfloop>
</cfoutput>
why it's not correct to write ..
Because FORM refers to a special system structure, not the name of your html form (ie fooform). FORM contains any form fields submitted via method=POST.
#myquery.recordcount#
btw, use cfdump to display anything. you see some really interesting stuff (I'm not sure whether recordcount is in there though)
getting to the elements:
<cfoutput query="queryname">#title#<br />#content#</cfoutput>
inside the cfoutput you have access to the variables of an element.
coldfusion 9 help