Groups | Blog | Home
all groups > flash data integration > february 2006 >

flash data integration : Dataset to Datagrid data search


amontes
2/3/2006 6:03:53 PM
I create my first ever Flash document.
I am using XMLConnector, DataSet and a DataGrid to connect to a Web Service
and display a directory of users in a Data grid.
Now I am trying to expand my application but I am hitting a wall because I
cannot find any information on this, anywhere not even using google.
I want to add a text box so when the user starts entering letters it will
select the row with that starting letter(s).
Does anybody know how to do this?
thanks

amontes
2/6/2006 4:57:28 PM
Does anybody read these messages???
Jpmon1
2/9/2006 4:54:23 PM
Try This:

Instead of using a text field, use a TextInput component and the following
actionscript:

If that does not work, you could use a "for loop" to pass through the values
in your data set when the input changes, it may take a while if you have alot
of names.

var listenerObject:Object = new Object();
listenerObject.change = function(eventObject:Object) {
dataSet.addSort("id", ["name","id"]);
if(dataSet.find([textInputInstance.text])){
ID = dataSet.getItemId();
dataGrid.focusedCell = {columnIndex:1, itemIndex:ID};
}
};
textInputInstance.addEventListener("change", listenerObject)
amontes
2/9/2006 6:55:25 PM
Thanks for the tip :D

I got it working but I noticed that ONLY when you type in the full value of
the search, it finds it.
for example
my grid has three columns (First Name, Last Name, Extension)
when I start typing something like... John
it does not find it until I type the full name, it does not do partial string
search.

I am working on this and hope to have a solution sometime in the future.

FYI: This is part of my code:
---------------------------

myDirReceiveXMLConnector.trigger();

var listenerObject:Object = new Object();
listenerObject.change = function (eventObject:Object) {
if (myDirDataSet.hasSort("FirstName")){
myDirDataSet.useSort("FirstName");
}else{
myDirDataSet.addSort("FirstName",["FirstName"]);
}
trace([txtInput.text] + ' ' + myDirDataSet.findFirst([txtInput.text]));
if (myDirDataSet.find([txtInput.text])) {
trace([txtInput.text]);
Extension = myDirDataSet.getItemId();
myDirDataGrid.focusedCell = {columnIndex:1, itemIndex:ID};
}
};
txtInput.addEventListener("change", listenerObject);
amontes
2/10/2006 12:19:16 AM
:P
This is for anybody that is looking for something like this:
.Datagrid
.txtInput
.Dataset
.XMLConnector
and some web service
in this example I am connecting to a user directory (XML)
.First Name
.Last Name
.Extension
(this is just an example and this is my first time doing this, I do not know
if this is the best way but it works!!!).
:beer; cheers!
--------------

import mx.controls.gridclasses.DataGridColumn;
myDirDataGrid.doLater(this,'updateCols');
myDirReceiveXMLConnector.trigger();

var listenerObject:Object = new Object();
listenerObject.change = function (eventObject:Object) {
if (myDirDataSet.hasSort("FirstName")){
myDirDataSet.useSort("FirstName");
}else{
myDirDataSet.addSort("FirstName",["FirstName"]);
}

var index:Number;
var strTmp:String;
var txtTmp:String;
try{
myDirDataSet.first();
while (myDirDataSet.hasNext()) {
strTmp = myDirDataSet.currentItem.FirstName.toString().toLowerCase();
txtTmp = [txtInput.text].toString().toLowerCase();
index = strTmp.indexOf(txtTmp);
if (index == 0)
break;
myDirDataSet.next();
}
}catch(myError:Error){
trace('error cauaght: ' + myError);
}

if (index == 0) {
Extension = myDirDataSet.getItemId();
myDirDataGrid.focusedCell = {columnIndex:1, itemIndex:ID};
index = myDirDataGrid.selectedIndex;
myDirDataGrid.vPosition = index;
}
};

function updateCols() {
var dgCol = myDirDataGrid.getColumnAt(0);
dgCol.headerText = 'First Name';
dgCol = myDirDataGrid.getColumnAt(1);
dgCol.headerText = 'Last Name';
}

txtInput.addEventListener("change", listenerObject);
txtInput.setFocus();
AddThis Social Bookmark Button