PDA

View Full Version : Has anyone used Grid paging with ColdFusion



kordsmen
3 Aug 2007, 5:28 AM
The Paging Grid demo is vary intriguing but we are a ColdFusion shop. Has any one figured out
how to utilize this functionality in a ColdFusion environment?

cbetancourt
11 Aug 2007, 3:38 PM
The backend has nothing to do with how pagination works, just make sure to create a properly formatted result in XML or JSON (look at the Ext examples for that).

Take a look at this (CF Verity) search (http://www.djindexes.com/search.cfm?criteria=dow) that uses Ext.Grid with pagination.

aconran
12 Aug 2007, 9:44 AM
Very cool site. Great to see others using CF with Ext.

Does that entire site run CF or just that grid? Are you running Adobe's Engine? What version of CF?

nbailey
13 Aug 2007, 9:16 AM
We struggled a bit at first, but once you get the hang of it it moves along rather quickly. we make extensive use of Ext grids - paginated and non-paginated.

More than once the other developers here have helped us out when we had a question, and I for one would love an opportunity to return the favor. What exactly are you stuck on? I'll see what I can do to help you out.

nb

dangerzone
14 Aug 2007, 6:15 PM
just query your data, then fill structures. this might wirk with the paging example:




<!--- set some parameters --->
<cfparam name="Form.start" default="1" />
<cfparam name="Form.limit" default="15" />


<cfscript>
thestruct = StructNew();
thestruct['totalCount'] = StructNew();
thestruct['totalCount'] = mainQuery.recordCount;
thestruct['topics'] = ArrayNew(1);
</cfscript>
<cfset numColumns = yourQuery.getColumnCount()>


<cftry>
<cfoutput query="yourQuery">
<cfloop from="#Form.start#" to="#Form.start + Form.limit#" index="i">
<!--- create the structure --->
<cfset thestruct.topics[i] = StructNew()>
<cfloop list="#mainQuery.ColumnList#" index="column">
<!--- fill the structure --->
<cfset cellTextValue = Replace(yourQuery[column][i], chr(13) & chr(10), ' ','ALL') />
<cfset cellTextValue = REReplace(cellTextValue, '[[:space:]]{2,}', ' ','ALL') />
<cfset thestruct.topics[i][column] = cellTextValue/>
</cfloop>
<!--- [END:: Rows] --->
</cfloop>
</cfoutput>

<cfcatch type="any">
<!--- error handler here --->
</cfcatch>
</cftry>

<!--- Then encode: #jsonencode(thestruct)#--->






then use jsonencode to encode the structure in json format:








<cfscript>

function jsonencode(arg) {
var i=0;
var o="";
var u="";
var v="";
var z="";
var r="";

if (isarray(arg)) {
o="";
for(i=1;i lte arraylen(arg);i=i+1) {
try {
v = jsonencode(arg[i]);
if (o neq "") {
o = o & ',';
}
o = o & v;
}
catch(Any ex){
o=o;
}
}
return '['& o &']';
}
if (isstruct(arg)) {
o = "";
if (structisempty(arg)) return "{null}";
z = StructKeyArray(arg);
for (i=1;i lte arrayLen(z);i=i+1) {
try {
v = jsonencode(evaluate("arg."&z[i]));
} catch(Any err) { WriteOutput("caught an error when trying to evaluate z[i] where i="& i &" it evals to " & z[i] ); }
if (o neq ""){
o = o & ",";
}
o = o & '"'& lcase(z[i]) & '":' & v;
}
return '{' & o & '}';
}

if (isobject(arg)) return "unknown";

if (issimplevalue(arg) and isnumeric(arg)) return ToString(arg);

if (issimplevalue(arg)) return '"' & JSStringFormat(ToString(arg)) & '"';

if (IsQuery(arg)){
o = o & '"RECORDCOUNT":' & arg.recordcount;
o = o & ',"COLUMNLIST":'&jsonencode(arg.columnlist);
// do the data [].column
o = o & ',"DATA":{';
// loop through the columns
for (i=1;i lte listlen(arg.columnlist);i=i+1){
v = "";
// loop throw the records
for (z=1;z lte arg.recordcount;z=z+1){
if (v neq "") {
v =v & ",";
}
// encode this cell
v = v & jsonencode(evaluate("arg." & listgetat(arg.columnlist,i) & "["& z & "]"));
}
// put this column in the output
if (i neq 1) {
o = o & ",";
}
o = o & '"' & listgetat(arg.columnlist,i) & '":[' & v & ']';
}
// close our data section
o = o & '}';
// put the query struct in the output
return '{' & o & '}';
}
return "unknown";
}
</cfscript>



hope this helps