Welcome, Guest
  • Author Topic: Searching a dataset and displaying results in datagrid  (Read 5971 times)

    Nate Elston

    • Server what's that
    • *
    • Posts: 4
      • View Profile
      • Email
    Hello All,
    I am working to search a bunch of data in a dataset and display the results in a datagrid and I have been working on this for a while and I have come up with the following code:

    //first empty the previous found set
    foundset_ds.clear();
    data1_ds.addSort("description", ["description", "trackID"]);
    if(data1_ds.find(searchTerm)) {
    foundset_ds.addItem(data1_ds(data1_ds.getItemId()));
    }

    And I have the datagrid bound to the 'foundset_ds'.

    Am I missing anything?  I know the data is being read into data1_ds properly becuase it is displayed in another datagrid for debugging purposes.  Any help into getting this to work would be greatly apprecited, sorry I am a little light on the details if you need to know anything let me know.
    Thanks
    Nate

    Jorge Solis

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 14616
      • View Profile
    Since the find method set the searched term as the selected item, you can simply copy the row:

    if(data1_ds.find(searchTerm)) {
      foundset_ds.addItem(data1_ds.currentItem);
    }

    Jorge

    Nate Elston

    • Server what's that
    • *
    • Posts: 4
      • View Profile
      • Email
    Thanks for your help.  But I have to be missing something because it is not working at all, I don't have any idea why it won't I have implemented the changes you said and I tried it with a while loop but still nothing.  Any other suggestions, do I have to refresh something else?
    Thanks
    Nate

    Jorge Solis

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 14616
      • View Profile
    Yep, there're some bugs in the dataset.find method, check http://www.macromedia.com/cfusion/knowledgebase/index.cfm?id=tn_19362

    A manual approach:

    Drag a couple of dataset named "data1_ds" and "foundset_ds" plus a button (not a component) named "myButton". Use this code:


    function search(searchTerm){
       for(var 
    z in data1_ds.items)
       if(
    data1_ds.items[z].Name==searchTerm){
          
    trace("Match !!")
            
    foundset_ds.addItem(data1_ds.items[z]);
       }
    }
    for(
    i=0i<10i++) data1_ds.addItem({Name:"Name"+i})
    listener = {}
    listener.modelChanged = function (evt) {
      for(var 
    i in evt.target.itemstrace(evt.target.items[i].Name)
    }
    foundset_ds.addEventListener("modelChanged"listener)
    myButton.onPress = function(){
       
    this._parent.search("Name5")
    }


    The foundset_ds dataset will store the searched term

    Jorge
    « Last Edit: 08/15/07, 02:28 by Jorge Solis »

    da288

    • Server what's that
    • *
    • Posts: 17
      • View Profile
    Your "searchTerms" must be in array format e.g.: dataset.find([var1]) or ["string1"] etc. That should help.