all groups > coldfusion flash integration > december 2005 >
You're in the

coldfusion flash integration

group:

Select Multiple Rows within CFGRID?


Select Multiple Rows within CFGRID? roninDLC
12/12/2005 3:21:52 PM
coldfusion flash integration:
Is it possible to select multiple records within a CFGRID?
Re: Select Multiple Rows within CFGRID? bradwood.com
12/23/2005 1:19:08 AM
http://livedocs.macromedia.com/flash/mx2004/main_7_2/00002232.html
Is lists all of the methods, properites, and events for the datagrid class.
This simple line of action script will allow my users to use the contorl-click
and shift-click multiple highlight functinality:
datagrid.multipleSelection = true;
And this property returns an array of selected indicies:
datagrid.selectedIndices

Re: Select Multiple Rows within CFGRID? roninDLC
1/5/2006 7:53:22 PM
Re: Select Multiple Rows within CFGRID? Pedro Claudio
1/6/2006 5:45:14 AM
<cfscript>
query = QueryNew('');
QueryAddColumn(query,'nome',ListToArray('Pedro, Pedro CLaudio'));
QueryAddColumn(query,'email',ListToArray('Pedro@email.com,
Pedro_CLaudio@email.com'));
</cfscript>
<cfform name="form1" format="flash" width="600" height="530">
<cfgrid name="grid" query="query" rowheaders="no" selectmode="edit">
<cfgridcolumn name="nome" header="Nome" width="260" />
<cfgridcolumn name="email" header="E-mail" />
</cfgrid>
<cfsavecontent variable="actionscript">
if(_root.grid.dataProvider.length>0){
for(var i = 0; i < _root.grid.dataProvider.length; i++){
_root.grid.dataProvider.editField(i, 'nome',
_root.grid.dataProvider.nome+' ');
}
}
_root.submitForm();
</cfsavecontent>
<cfinput type="button" name="send" value="send" onClick="#actionscript#" />
</cfform>
<cfdump var="#FORM#" />

Re: Select Multiple Rows within CFGRID? roninDLC
1/6/2006 3:53:43 PM
It seems that the example above selects all records in the grid. Maybe I
miscommunicated. Let me post my code. What is needed is to pass the multiple
user-selected records after submit has been pushed. Keep in mind that I am an
actionscript noob. Thanks again.




<!--- Retrieve Case Types --->
<cfinvoke
component="labels.functions.labels"
method="fnGetCaseType"
datasource="#application.ds#"
returnvariable="rsGetCaseType">

<!--- Remember User-Entered Form Vars --->
<cfparam name="session.user.caseyear" default="5">
<cfparam name="session.user.casenumber" default="">
<cfparam name="session.user.terminated" default="">
<cfparam name="session.user.office" default="1">
<cfparam name="session.user.casetype" default="cv">
<cfparam name="session.user.nef" default="">
<cfparam name="session.user.labeltype" default="wrapper">


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Attorney Label System</title>
<style >
html, body{
height:100%;
margin:0;
}
body{
background: #202020 url(assets/images/patternBg.gif);
}
#container{
margin: auto;
background: #195075 url(assets/images/background.gif) center center repeat-x;
width: 990px;
border: 1px solid #222;
height: 100%;
}
</style>
</head>
<body>
<table id="container">
<tr>
<td>
<cfform
name="attorneySearch"
format="flash"
method="post"
action="labelsprint.cfm"
skin="haloblue"
width="990"
height="610"
preloader="true"
timeout="60"
onload="formOnLoad()"
style="themeColor:##56A1E1; marginRight:0; background-color:##37749D;">


<cfformitem type="script">
public function formOnLoad(){
attorneySearch.myGlobalObjects = {};
<!--- set up remoting service --->
setUpRemoting();
<!--- set up styles --->
setStyles();
}

public function setUpRemoting(){
var connection:mx.remoting.Connection =
mx.remoting.NetServices.createGatewayConnection("http://localhost/flashservices/
gateway/");
var componentPath = "Applications.labels.services.labelservice";
var myService:mx.remoting.NetServiceProxy;
var responseHandler:Object = {};

<!--- put controls in function scope --->
var listingGrid:mx.controls.DataGrid = listingGrid;

<!--- handle search by default onResult function --->
responseHandler.onResult = function( results: Object ):Void {
listingGrid.dataProvider = results;
listingGrid.selectedIndex = undefined;
listingGrid.multipleSelection = true;
mx.managers.CursorManager.removeBusyCursor();
//show a message
alert(listingGrid.dataProvider.length + " Attorneys Found." , "Results");
}

<!--- default error handler --->
responseHandler.onStatus = function( stat: Object ):Void {
//if there is any error, show an alert
alert("Error: " + stat.description);
mx.managers.CursorManager.removeBusyCursor();
}

<!--- store service in global variable --->
attorneySearch.myGlobalObjects.labelservice =
connection.getService(componentPath, responseHandler );
}

public function setStyles():Void {
_global.styles.ComboBox.setStyle("color", 0x00253D);
_global.styles.Label.setStyle("color", 0x222222);
_global.styles.CheckBox.setStyle("color", 0x00253D);
_global.styles.RadioButton.setStyle("color", 0x00253D);
_global.styles.Form.setStyle("color", 0x222222);
_global.styles.Button.setStyle("color", 0x222222);
_global.styles.Button.setStyle("borderThickness", 1);
_global.styles.Panel.setStyle("backgroundColor", 0xE5F0F9);
_global.styles.Panel.setStyle("color", 0xffffff);
_global.styles.Panel.setStyle("headerColors", [0x277DC6,0x50ABF7]);
}


<!--- this function is called when search button is clicked --->
public function submitSearch():Void {
<!--- get all the search criteria items --->
var searchArguments = {};
<!--- simple text input --->
searchArguments.caseyear = caseyear.text;
searchArguments.casenumber = casenumber.text;
<!--- checkboxes --->
searchArguments.terminated = terminated.selected;
searchArguments.nef = nef.selected;
<!--- dropdowns --->
searchArguments.office = office.selectedItem.data;
searchArguments.casetype = casetype.selectedItem.data;
<!--- show clock cursor --->
mx.managers.CursorManager.setBusyCursor();
<!--- call service --->
attorneySearch.myGlobalObjects.labelservice.search(searchArguments);
}

</cfformitem>

<cfformgroup type="hbox" width="990">
<!--- logo --->
<cfformgroup type="panel" width="218" style="headerHeight: 0; cornerRadius:
0;">
<cfformitem type="spacer"/>
<cfformitem type="html" name="imageDisplay" height="125" width="198"><img
src='assets/images/labels.jpg' /></cfformitem>
<cfformitem type="spacer"/>
</cfformgroup>

<!--- Search panel --->
<cfformgroup type="Panel" label="Search" style="indicatorGap:0;
verticalGap:5;" width="750" height="180" >
<cfformgroup type="vertical">
<cfformgroup type="horizontal">
<cfformitem type="spacer"/>
<cfselect
name="office"
width="100"
label="Office:">
<option value="1" <cfif #session.user.office# eq 1>selected</cfif> >El
Dorado</option>
<option value="2" <cfif #session.user.office# eq 2>selected</cfif>>Fort
Smith</option>
<option value="3" <cfif #session.user.office# eq
3>selected</cfif>>Harrison</option>
<option value="4" <cfif #session.user.office# eq
4>selected</cfif>>Texarkana</option>
<option value="5" <cfif #session.user.office# eq
5>selected</cfif>>Fayetteville</option>
<option value="6" <cfif #session.user.office# eq 6>selected</cfif>>Hot
Springs</option>
</cfselect>
<cfinput name="caseyear" width="40" label="Year:"
value="#session.user.caseyear#" validate="integer" maxlength="4">
<cfselect
name="casetype"
width="135"
query="rsGetCaseType"
value="type"
queryPosition="below"
display="description"
selected="#session.user.casetype#"
label="Case Type:">
</cfselect>
<cfinput name="casenumber" width="50" label="Number:"
value="#session.user.casenumber#" maxlength="5">
<cfformitem type="spacer"/>
</cfformgroup>
<cfformgroup type="horizontal">
<cfformitem type="spacer"/>
<cfif isdefined('session.user.terminated') and #session.user.terminated#
neq '1'>
<cfinput type="checkbox" name="terminated" label="Include terminated
attorneys">
<cfelse>
Re: Select Multiple Rows within CFGRID? Pedro Claudio
1/6/2006 4:19:40 PM
I did not use its code not to confuse

<cfscript>
query = QueryNew('');
QueryAddColumn(query,'nome',ListToArray('Pedro,Pedro Claudio,pcsilva'));

QueryAddColumn(query,'email',ListToArray('Pedro@email.com,Pedro_CLaudio@email.c
om,pcsilva@email.com'));
</cfscript>
<cfform name="form1" format="flash" width="600" height="530"
onload="loadAS();">
<cfformitem type="script">
function loadAS(){
_root.grid.multipleSelection = true;
}
</cfformitem>
<cfgrid name="grid" query="query" rowheaders="no">
<cfgridcolumn name="nome" header="Nome" width="260" />
<cfgridcolumn name="email" header="E-mail" />
</cfgrid>
<cfsavecontent variable="actionscript">
if(_root.grid.selectedIndices != null){
for(var i = 0; i < _root.grid.selectedIndices.length; i++){
var index = _root.grid.selectedIndices;
_root.grid.dataProvider.editField(index, 'nome',
_root.grid.dataProvider[index].nome+' ');
}
}
_root.submitForm();
</cfsavecontent>
<cfinput type="button" name="send" value="send" onClick="#actionscript#" />
</cfform>
<cfdump var="#FORM#" />

Re: Select Multiple Rows within CFGRID? roninDLC
1/6/2006 5:20:59 PM
Pedro, the code is does not appear to be working properly. Sorry about the
formatting, but here is what is returned when selecting multiple records from
your code. Am I doing something wrong?

The <cfdump var="#form#"> is returning...

FIELDNAMES: __CFGRID__FORM1__GRID
GRID.EMAIL: array 1 undefined
GRID.NOME: array 1 undefined
GRID.ORIGINAL.EMAIL: array 1 [empty string]
GRID.ORIGINAL.NOME: array 1 [empty string]
GRID.ROWSTATUS.ACTION: array 1 U
__CFGRID__FORM1__GRID
__CFGRID__EDIT__=2nomeYemailY1Uundefinedundefined

Thanks very much for your help!

Re: Select Multiple Rows within CFGRID? Pedro Claudio
1/6/2006 5:43:24 PM
Re: Select Multiple Rows within CFGRID? Pedro Claudio
1/6/2006 5:56:44 PM
it looks at the result
Re: Select Multiple Rows within CFGRID? roninDLC
1/6/2006 7:25:32 PM
I have version 7,0,1,116466 . Please take a look....

Re: Select Multiple Rows within CFGRID? Pedro Claudio
1/7/2006 2:40:19 AM
The only way of this mistake occur are you be using an index with an index
value for a line of grid that does not exist.
For example, in this grid have 3 elements, which they can be called by an
index value from 0 to 2, then for provoke this mistake you could place as index
the number 3, or any number greater than 2, that why the array in actionscript
initiates the counting of the zero.


it tries thus, instead of placing a fixed value for index

<cfscript>
query = QueryNew('');
QueryAddColumn(query,'nome',ListToArray('Pedro, Pedro CLaudio'));
QueryAddColumn(query,'email',ListToArray('Pedro@email.com,
Pedro_CLaudio@email.com'));
</cfscript>
<cfform name="form1" format="flash" width="600" height="530">
<cfgrid name="grid" query="query" rowheaders="no" selectmode="edit">
<cfgridcolumn name="nome" header="Nome" width="260" />
<cfgridcolumn name="email" header="E-mail" />
</cfgrid>
<cfsavecontent variable="actionscript">
if(_root.grid.dataProvider.length>0){
for(var i = 0; i < _root.grid.dataProvider.length; i++){
_root.grid.dataProvider.editField(i, 'nome', _root.grid.dataProvider.nome+' ');
}
_root.submitForm();
}else{
alert('it selects an item please');
}

</cfsavecontent>
<cfinput type="button" name="send" value="send" onClick="#actionscript#" />
</cfform>
<cfdump var="#FORM#" />




Re: Select Multiple Rows within CFGRID? roninDLC
1/9/2006 4:08:25 PM
Pedro, that works great for a query! Thanks very much. Is it possible to get
it to work with populated data that was retrieved from flash remoting? Would I
just need to change a variable name?

Thanks again!
Re: Select Multiple Rows within CFGRID? Pedro Claudio
1/9/2006 6:29:46 PM
it observes results._items



<cfform name="form1" format="flash" width="600" height="250"
onload="loadAS();">
<cfformitem type="script">
function loadAS(){
_root.grid.multipleSelection = true;
}
</cfformitem>
<cfgrid name="grid" rowheaders="no">
<cfgridcolumn name="nome" header="Nome" width="260" />
<cfgridcolumn name="email" header="E-mail" />
</cfgrid>
<cfsavecontent variable="actionscript">
if(_root.grid.selectedIndices != null){
var arr_data:Array = _root.grid.selectedIndices;
while(arr_data.length > 0 ){
var index = arr_data.pop();
_root.grid.dataProvider.editField(index, 'nome',
_root.grid.dataProvider[index].nome+' ');
}
_root.submitForm();
}else{
alert('');
}
</cfsavecontent>
<cfinput type="button" name="send" value="send" onClick="#actionscript#" />
<cfsavecontent variable="actionscript">
mx.managers.CursorManager.setBusyCursor();
var conn:mx.remoting.Connection;
var Proxy:mx.remoting.NetServiceProxy;
var response={};
var gateway ='http://localhost:8080/cfusion/flashservices/gateway/';
conn = mx.remoting.NetServices.createGatewayConnection(gateway);
response.onStatus = function(stat:Object):Void {
alert("Error: " + stat.description);
mx.managers.CursorManager.removeBusyCursor();
};
response.onResult = function(results:Object):Void {
if(results){
_root.grid.dataProvider = results._items;
}else{
alert("error - loged");
}
mx.managers.CursorManager.removeBusyCursor();
};
Proxy = conn.getService('cfcomp', response);
Proxy.getData();
</cfsavecontent>
<cfinput type="button" name="get" value="get" onClick="#actionscript#" />
</cfform>
<cfdump var="#FORM#" />

<cfcomponent>
<cffunction name="getData" access="remote" returntype="query">
<cfscript>
var query = QueryNew('');
QueryAddColumn(query,'nome',ListToArray('Pedro,Pedro Claudio,pcsilva'));

QueryAddColumn(query,'email',ListToArray('Pedro@email.com,Pedro_CLaudio@email
..com,pcsilva@email.com'));
</cfscript>
<cfreturn query />
</cffunction>
</cfcomponent>
AddThis Social Bookmark Button