Unoffical empeg BBS

Quick Links: Empeg FAQ | RioCar.Org | Hijack | BigDisk Builder | jEmplode | emphatic
Repairs: Repairs

Topic Options
#229143 - 31/07/2004 17:03 Flash MX 2004 datagrid problem...
JBjorgen
carpal tunnel

Registered: 19/01/2002
Posts: 3584
Loc: Columbus, OH
I've been trying to figure out this problem for a couple days.

My wife says "why don't you just post it on the empeg forums, those guys know everything."

I told her that I don't think there are any Flash wonks on here, but that I'd test the theory that you guys can answer any question...so without further ado:

I have a datagrid that is populated by the results of a remoting query(amfphp). The data displays just fine. However, whenever I try to edit any of the data, it changes back to the old value before the cellEdit event can even fire.

It specifically has something to do with how the datagrid binds itself to the data. For example take gradebook2.swf.

The data is bound to the datagrid like so:

Code:

myDP = new Array();
myDP.push( new Array("","","","","","","","","","","","","",98,34,89,76,45) )
myDP.push( new Array("","","","","","","","","","","","","",98,34,89,76,45) )
myDP.push( new Array("","","","","","","","","","","","","",98,34,89,76,45) )
myDP.push( new Array("","","","","","","","","","","","","",98,34,89,76,45) )

spMain.content.centerGrid.dataProvider = myDP;



You'll notice that you can change the data in the grid.

Now take a look at gradebook3.swf (note: you'll have to select a course and quarter to get some data in this one).

The data is bound to the datagrid like so:

Code:


GradeBook.getGrades(getGradesReply, SchoolID, TeacherID, ddCourse.value, ddQuarter.value);

var getGradesReply = new Object();
getGradesReply.onResult = function(result) {
spMain.content.centerGrid.removeAllColumns();
spMain.content.centerGrid.dataProvider = result;
}



As soon as the grid is bound to the result of a recordset, it ceases to allow me to edit
any of the data in the grid. Source code for the two movies is gradebook2.fla and gradebook3.fla.

Thanks again.

John

Top
#229144 - 01/08/2004 00:18 Re: Flash MX 2004 datagrid problem... [Re: JBjorgen]
JBjorgen
carpal tunnel

Registered: 19/01/2002
Posts: 3584
Loc: Columbus, OH
Well...I figured out a solution. It seems kinda clunky, but sometimes whatever gets the job done is the right way to do it.

Anyone interested in my solution can read on...

Through much scouring of the web, I discovered that if I bound my DataGrid to a DataSet component, it would magically allow me to edit the contents of the DataGrid. Being new to Flash/actionscript, I'm not sure if that is just "The Way it Works" or if I'm still missing something simple. I don't know why I would be allowed to edit the contents of the DataGrid when it is bound to an array, but not when it is bound to a recordset. Come to think of it, now that I've got one solution, I could probably have just converted the recordset into a two dimensional array and have been done with it. Bah! too easy (although probably faster and I may do it yet.) Anyhow, I digress. From there it was simply a matter of defining a DataSet schema dynamically, setting up my DataGrid columns to match the DataSet schema, and binding them to my data source and each other. Hmm...actually that sounds pretty easy now....why the #$% did it take me so long to figure that out? And why am I taking a mental diarrhea on the BBS? I guess as long as it only happens once in a blue moon it's ok...Now where was I? Oh...right defining the schema, etc...The only problem with doing it this way is that it requires another database query, which I'm trying to keep to a minimum because some of my end-users will most likely be serving up the data over a DSL or Cable connection. Oh well, it's already taken too much of my time, so they'll just have to deal. If there's anyone still reading at this point and still interested, here's the applicable code:

Code:

GradeBook.getColumns(getColumnsReply, SchoolID, TeacherID, ddCourse.value, ddQuarter.value);

var getColumnsReply = new Object();
getColumnsReply.onResult = function(result) {
spMain.content.centerGrid.removeAllColumns();
var myschema = "<properties>";
// Count backwards because otherwise the stupid DataGrid displays everything in reverse order....bleh!
for (var i=(result.length-1);i>=0; i--) {
spMain.content.centerGrid.columnNames[i] = result.items[i].TaskID;
myschema += "<property name=\"" + result.items[i].TaskID + "\"><type name=\"String\" original=\"false\">";
myschema += "<validation className=\"mx.data.types.Str\"><settings /></validation></type></property>";
}
myschema += "</properties>";
dataset1_ds.schema = new XML(myschema);
GradeBook.getGrades(getGradesReply, SchoolID, TeacherID, ddCourse.value, ddQuarter.value);
}

var getGradesReply = new Object();
getGradesReply.onResult = function(result) {
dataset1_ds.dataProvider = result;
spMain.content.centerGrid.dataProvider = dataset1_ds.dataProvider;
}


_________________________
~ John

Top
#229145 - 01/08/2004 00:31 Re: Flash MX 2004 datagrid problem... [Re: JBjorgen]
JBjorgen
carpal tunnel

Registered: 19/01/2002
Posts: 3584
Loc: Columbus, OH
Follow up: I guess my wife was right...Someone on the BBS did figure it out...although, somehow I'm not sure that since it was ME that figured it out, that it still counts....

We'll call this one a draw.
_________________________
~ John

Top
#229146 - 01/08/2004 14:25 Re: Flash MX 2004 datagrid problem... [Re: JBjorgen]
wfaulk
carpal tunnel

Registered: 25/12/2000
Posts: 16706
Loc: Raleigh, NC US
Not knowing the first thing about Actionscript, I'll take a stab in the dark. Perhaps arrays are mutable while recordsets are not?
_________________________
Bitt Faulk

Top
#229147 - 01/08/2004 23:18 Re: Flash MX 2004 datagrid problem... [Re: wfaulk]
JBjorgen
carpal tunnel

Registered: 19/01/2002
Posts: 3584
Loc: Columbus, OH
Could be. I posted this on 3 flash forums and yours is the only decent answer I got.
_________________________
~ John

Top
#229148 - 02/08/2004 05:56 Re: Flash MX 2004 datagrid problem... [Re: JBjorgen]
Cybjorg
addict

Registered: 23/12/2002
Posts: 652
Loc: Winston Salem, NC
I knew you could figure it out.

Top
#229149 - 17/06/2005 07:52 Re: Flash MX 2004 datagrid problem... [Re: JBjorgen]
log2e
new poster

Registered: 17/06/2005
Posts: 1
Quote:
From there it was simply a matter of defining a DataSet schema dynamically, setting up my DataGrid columns to match the DataSet schema, and binding them to my data source and each other


Sorry for bringing up this old thread. But how did you fill the "DataSet.items"? Did you set up a dynamic binding between an XMLConnector and the DataSet? How did you do that only using ActionScript code (no inspector panels)?

Top
#229150 - 17/06/2005 16:20 Re: Flash MX 2004 datagrid problem... [Re: log2e]
JBjorgen
carpal tunnel

Registered: 19/01/2002
Posts: 3584
Loc: Columbus, OH
Doh! Forgot to reply to your email. Next time I'm at the office I'll let you know and get you some sample code.
_________________________
~ John

Top