PDA

View Full Version : Target row/datafield in data-grid


rogueblade
02-22-2010, 07:08 PM
Hey guys I have a data-grid which is pulling information from a database through php (zend-amf)

<mx:DataGrid id="reservationTbl" dataProvider="{amfcall.getReservations.lastResult}" editable="false" change="editReservation()" >
<mx:columns>
<mx:DataGridColumn headerText="Date" dataField="res_date" />
<mx:DataGridColumn headerText="Time" dataField="res_time" />
<mx:DataGridColumn headerText="Name" dataField="res_name" />
<mx:DataGridColumn headerText="Party Size" dataField="res_size" />
<mx:DataGridColumn headerText="Table" dataField="table_num" />
<mx:DataGridColumn headerText="Status" dataField="res_status" />
</mx:columns>
</mx:DataGrid>

In my script I am trying to make a function which causes an event if a particular dataField from any of my Rows equals a certain criteria. Thing is I don't know how to target a data field or row. The only way I have targeted a row is with a change/click event on the data-grid itself which then populates a form.

I have a form item in which you input a number for the Party Size (res_size) and what I want is my function to check if the value in my form input is larger/different than what already exists in the database/grid. But I can't target the data field! Any idea how I can do this.

box86rowh
02-22-2010, 09:38 PM
you can just target the dataProvider, like :

myGrid.dataProvider[4].res_size;

rogueblade
02-23-2010, 12:21 AM
Hmm upon trying this I get the error
RangeError: Index '4' specified is out of bounds.
Or whatever number I put in the brackets. Am I correct in assuming that this is some sort of array collection of the data providers?

rogueblade
02-23-2010, 12:30 AM
ok I take that back. If I put
myGrid.dataProvider[1].res_size;
it does work, but no other number will.....are you able to explain why this is??

box86rowh
02-23-2010, 01:35 AM
depends on how many records in the datagrid, 4 would be the fifth record in the set, 1 is the second one, as the set is zero indexed

rogueblade
02-23-2010, 01:35 AM
I currently have 5 which is why I'm baffled

rogueblade
02-23-2010, 02:25 AM
Ok nevermind mind I was making a stupid mistake, what you said does work thankyou. But what I would like to figure out now is how to check multiple datafields
So I tired this:
myGrid.dataProvider[0,1,2,3,4].res_size;
But that gives me this error:
"ReferenceError: Error #1069: Property 4 not found on Number and there is no default value."
Or what ever is the lat number I put is the the number present in the error.

Do you know if I can check multiple data fields at the same time like what I'm trying to do in my example?

rogueblade
02-23-2010, 11:14 PM
But does anyone know how I can target more than one datafield in a dataprovider, like my attempted example above?

box86rowh
02-24-2010, 04:13 AM
what is the scenario where u are checking multiple rows?

rogueblade
02-24-2010, 04:22 AM
When I enter the party size for a reservation (left red circle) I want to check the "size" colum (right red circle) which is the number of seats a table has. This is so that I can flag all the tables which are smaller (less seats) than the number inputted in the form label "party size"
http://i50.tinypic.com/29w3bkj.jpg

I was thinking of doing a loop in the script myGrid.dataProvider[i].res_size; but I wouldn't know what to tell 'i' to be greater/less than. In the php I could run a query to get the number of rows, but I don't know how to send that information to flex so I can use it in a loop function.

box86rowh
02-24-2010, 03:03 PM
you can do a for loop on dataProvider.length() like:

for(var i:Number = 0; i < YOURGRID.dataProvider.length; i++){
//access the current row using i as the index
}

box86rowh
02-24-2010, 03:04 PM
depending on the type of data you are using, you may need to add () after the length in the for loop, try it if it does not work as is

rogueblade
02-25-2010, 01:17 AM
Awesome, thanks man that works so far. It's a shame I couldn't figure that out on my own, kinda stupid of me not to realize I could have done that having done it many times before...

Here is what I have working now for sake of getting the function to work like you've done for me.
public function acceptTables():void {
for (var i:int = 0; i < availableTables.dataProvider.length; i++) {
if (ressize.text == availableTables.dataProvider[i].table_seats ) {
ressize.text = "bazinga!"; //the form input box
}
}
}

But what I actually want to be able to do is change the Style (colour, size etc) of the datafields that have been found to meet the requiremnts of my if statement in the function
(IF ressize.text == availableTables.dataProvider[i].table_seats)

Here's my attempt to give you an idea of what I'm trying. Thing is I don't know how to target a style property through actionscript. Is this possible?

public function acceptTables():void {
for (var i:int = 0; i < availableTables.dataProvider.length; i++) {
if (ressize.text == availableTables.dataProvider[i].table_seats ) {
availableTables.dataProvider[i].table_seats.color = "red";
}
}
}
error tells me "Cannot create property color on Number."