View Full Version : bind DataSet to DataGrid
black
05-09-2004, 02:55 AM
hi all~
here i have already gathered data(records from database) into DataSet and next need to flow those data to DataGrid optionally, for example i want DataGrid hold only id and name columns from DataSet, any ideas ?
annexion
05-09-2004, 04:02 PM
var src = new mx.data.binding.EndPoint();
var dest = new mx.data.binding.EndPoint();
src.component = dataSet;
src.property = "dataProvider";
src.event = "modelChanged";
dest.component = dataGrid;
dest.property = "dataProvider";
dest.event = "modelChanged";
new Binding(src, dest,undefined,true);
That would be the data binding code. Now, you have one of two options for selectively displaying what you want.
Either set the headerNames of the dataGrid to what you want displayed with actionscript, or use the component inspector to assign the "columns" you want. The dataGrid will automatically associate the correct columns between the dataSet and the dataGrid.
As a sidenote: The code above assigns a two way binding. Meaning, if the dataGrid changes, the dataGrid will execute the binding and change the associated element in the dataSet. For one way, remove the dest.event = "modelChanged"; and also remove the "undefined" and "true" from the new Binding line.
black
05-11-2004, 02:19 AM
thanx i get it work ! really thanx~ :)
zapod
11-11-2004, 04:15 PM
I am getting strange results with dataProvider not binding the way i want it. well I dont get anything showing up although the array object do populate the grid rows correctly :confused:
import mx.data.binding.*;
_global.__dataLogger=new mx.data.binding.Log()
mtxt = '<Types><Type ID="A10531" Operation="J" Stand="102"/><Type ID="A105" Operation="J" Stand="101"/><Type ID="A10537" Operation="f" Stand="10"/></Types>';
var doc:XML = new XML(mtxt);
myDataSet.dataProvider = doc.firstChild.childNodes;
//trace(doc.firstChild.childNodes);
this.onLoad = function() {
var src = new EndPoint();
var dest = new EndPoint();
src.component = myDataSet;
src.property = "dataProvider";
src.component = myDataSet;
src.event = "modelChanged";
dest.component = myDataGrid;
dest.property = "dataProvider";
dest.event = "modelChanged";
new Binding(src, dest, undefined, true);
};
function mBind() {
trace(myDataSet.dataProvider.length+"="+myDataSet.dataProvider.getItemId(0)+" = "+myDataSet.dataProvider.getItemId(0));
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.