A Flash Developer Resource Site

Results 1 to 13 of 13

Thread: data grid and combo box

  1. #1
    Junior Member
    Join Date
    Oct 2004
    Posts
    12

    data grid and combo box

    Hi all,

    I am working on a CD project which involves XML and Flash. I have a problem here. I have a datagrid which extracts data from XML.

    What i want is to filter the data in the Grid based on the selection made in Combo Box. I.E if i select "M" in combo box i want the data related to "Male" to be displaye din the Datagrid.


    I am able to filter this thru command button but not with combo box's "ON CHANGE" event.

    I need one more info can we filter the data displayed in a combo box. I.e I have say some 100 records in XML i want to show only the first instances of a field. Say i have age, i want to display only the unique age alone.

    Is it possible.

    Any Idea how to go about this
    thanks in advance
    yathen

  2. #2
    Senior Member tokyo_sky's Avatar
    Join Date
    Oct 2004
    Location
    Tokyo
    Posts
    201
    try storing the data in a dataSet it has sort,find,etc abilities to long to go into but i think thats what your after?


    so finding all 'M's in field 'sex' then send that to the grid
    A spark of light in a dark wibbly wobbly world

  3. #3
    Junior Member
    Join Date
    Oct 2004
    Posts
    12

    data grid and combo box

    Hi tokyo_sky,

    The data is already stored in data set. but i am a bit new to this data binding stuff. you got any more suggestion about how to do this.

    thanks for your suggestion

    yathen

  4. #4
    Senior Member tokyo_sky's Avatar
    Join Date
    Oct 2004
    Location
    Tokyo
    Posts
    201
    In the following example, filtering is enabled on the DataSet object named record. The specified filter function returns true if the sex field in each item is set to "male"; otherwise, it returns false.

    record.filtered = true;
    record.filterFunc = function(item:Object) {
    // filter out females
    return(item.sex != "male");
    }
    A spark of light in a dark wibbly wobbly world

  5. #5
    Junior Member
    Join Date
    Oct 2004
    Posts
    12
    Hi tokyo_sky,

    I understand what your code means. and I have created one similar to this with buttons. I.E when button named maleis clicked the data is filetered to show "Male" and so.

    Now where i am struck is i try doing this with a combo box. I.E when Male is selected in combo i want the data to be filtered which is not happening at all.

    In the button i have used OnClick and it works fine. for the combo box i have used OnChange and have event handler too still it is not working.



    --------------------------- this is my filter code -------------

    setFilter = new Object();
    setFilter = function(request)
    {
    if (request == "all") {
    ds_contact.filtered = false;
    } else {
    ds_contact.filtered = true;
    ds_contact.filterFunc = function(item:Object) {
    return(item.sexe == (request == "M" ? "homme" : "femme"));
    }
    }
    }


    ------------------------- this is my combo box event handler ---

    //combo box
    myComboBoxListener = new Object();
    myComboBoxListener.change = function ( eventObj )
    {
    var eventSource = eventObj.target;

    var theSelectedItem = eventSource.selectedItem;
    var theSelectedItemLabel = theSelectedItem.data;

    msg = "You selected " + theSelectedItemLabel + ".";
    statusMessage.text = msg;
    this._parent.setFilter(theSelectedItemLabel);


    }

    cb_contacts.addEventListener ("change", myComboBoxListener);




    --------------------------- this is what i have in button to filter -

    on (click) {
    _parent.setFilter("F");
    }


    the button on click returns the value fine thru : _parent.setFilter("F");

    but when i use this with combo box it doesnt work out well.

    any idea what to do



    Yathen
    Last edited by yathen; 10-21-2004 at 04:32 AM.

  6. #6
    Senior Member tokyo_sky's Avatar
    Join Date
    Oct 2004
    Location
    Tokyo
    Posts
    201
    so
    var theSelectedItemLabel would = "f"?

    and try

    var theSelectedItemLabel = theSelectedItem.data.text
    to pass it a string...

    then trace every var you have to make sure that theSelectedItemLabel ends up as a string F or M...

    this._parent.setFilter(theSelectedItemLabel); is this the right path??...

    in truth its far easyer to test if you set up the button to do the listeners task at least to start with Imo.
    A spark of light in a dark wibbly wobbly world

  7. #7
    Junior Member
    Join Date
    Oct 2004
    Posts
    12
    Hi

    I am sure it will be easier to use button than combo box but i might be improvising on this and might need to filter the recodrs based on city or state.

    So u dont expect me to have so many button for filtering the records.

    Yathen

  8. #8
    Senior Member tokyo_sky's Avatar
    Join Date
    Oct 2004
    Location
    Tokyo
    Posts
    201
    no i meant instead of the listener use the button to trigger getting the info from the combo box to the filter
    A spark of light in a dark wibbly wobbly world

  9. #9
    Junior Member
    Join Date
    Oct 2004
    Posts
    12
    hi tokyo_sky

    seems to be a nice idea. but can u tell me how to do it.

    yathen

  10. #10
    Senior Member tokyo_sky's Avatar
    Join Date
    Oct 2004
    Location
    Tokyo
    Posts
    201
    on(press){
    var theSelectedItem = cb_contacts.selectedItem;
    var theSelectedItemLabel = theSelectedItem.data;

    msg = "You selected " + theSelectedItemLabel + ".";
    statusMessage.text = msg;
    this._parent.setFilter(theSelectedItemLabel);
    }

    maybe...

    on(press){

    targ = _root.combobox.selectedItem;
    obj = targ.data.text;
    this._parent.setFilter(obj);
    }

    i am guessing and doing it freehand
    A spark of light in a dark wibbly wobbly world

  11. #11
    Junior Member
    Join Date
    Oct 2004
    Posts
    12
    Hi Tokyo_sky

    I have tried that b4. can i have ur mail id so that i will send u those files so u can take a look at it

    yathen

  12. #12
    Senior Member tokyo_sky's Avatar
    Join Date
    Oct 2004
    Location
    Tokyo
    Posts
    201
    sent it to you via pm...
    A spark of light in a dark wibbly wobbly world

  13. #13
    Junior Member
    Join Date
    Oct 2004
    Posts
    12
    hi Tokyo_sky

    i have send the attachment to your mail.take a look

    yathen

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center