6 Replies Latest reply on Nov 4, 2008 1:22 PM by *gsb*

    XML - Get a list of possible values for filtering

    MacGyverMan
      Hi everyone,

      I have a bunch of data comming from AMFPHP to be edited via flex. The data is a combination of data joined from various SQL tables. The format is similar to:

      <date day='10/10/2008'>
      ....<grade grade_number='1'>
      ........<subject name='english'>
      ............<type name='homework'>
      ................<entry id='1'>
      ...................<entry_e>Create new homework</entry_e>
      ...................<date>10/10/2008</date>
      ...................<subject>10/10/2008</subject>
      ...................<adder>1</adder>
      ................</entry>
      ...

      I used to send this data over as an objet, then use a grouping collection and a filter function to pull out the relevant data when a used picked the date, grade, subject, type. This barely worked and caused allot of problems with binding. I get the impression the best solution is to use an EX4 object instead. For this to work however, I need the following information:
      - A list of all possible values for each grade, subject, date and type. These values would then be used to populate various controls to pick which fields to filter the data on as to allow the user to drill down to the entry they wish to edit.

      Am I on the right track with this idea? How do you get a unique list of all the possible values you can filter the dataset on? There is allot of discussion in books on how to filter data with an e4x expression, but little discussion on how to get all the possiblve values for that filter (for example to populate a combo box that would list the possible values)

      Also, when data is returned via an e4x expression, is it a copy or a pointer to the source data? I.E if I change the returned data, does that change it in the source data also?

      Thanks

      pierre
        • 1. Re: XML - Get a list of possible values for filtering
          dmindler
          quote:

          Am I on the right track with this idea?


          Yes

          quote:

          How do you get a unique list of all the possible values you can filter the dataset on?


          Can vary by implementation. In the ones I have worked on, when the app is initializing, I make HttpService calls to the backend to get a list of all possible values. These should be DB driven, so that if new values are added or old ones removed, the front-end does not have to change. My initialization call is named "dataListService" and it calls my "dataList.jsp" who returns a variety of list data that is used to populate the combo boxes.



          quote:

          Also, when data is returned via an e4x expression, is it a copy or a pointer to the source data?


          Typically, I point the visual component to the "lastResult" of the HttpService. The visual component can be changed without changing the "lastResult". In other words, bind the component text value to the last result. I then have a "cancel" button that re-executes the HttpService to get a fresh copy of the data (since it could have changed by someone else since the first retrieval).

          Hope this helps!

          • 2. Re: XML - Get a list of possible values for filtering
            MacGyverMan Level 1
            Sweet...thanks...I`ll have a look at it.

            So from what I gather you query the db quite often? I was trying to limit bandwith usage by downloading a copy of all the week's classes and then allowing the user to "save changes". I'm not too worried about getting a data collision since the classes are unique to each login.

            So there is no way to obtain the unique values from the dataset directly?
            • 3. Re: XML - Get a list of possible values for filtering
              dmindler Level 1
              I'm not sure how your application is designed, but doing a good job up front in data exchange design will save you tons of time/bandwidth later.

              In my app, there is semi-static, table-driven data (i.e., db lookup tables). This data does not change frequently (e.g., possible grades to assign a student "A,B,C,D,F").

              Then, the user starts querying the system (e.g., list of students in a course). In the result from the query, information can be changed (e.g., assign the student a grade from the pulldown). Once all changes have been made, a "Save" can be issued. A "Cancel" would pull down new data (i.e., re-run the last query) and reset the viewable screen to an un-modified state.


              quote:

              So from what I gather you query the db quite often?


              Not really. Loading the initial list of data can be slow... but we've done things like caching on the server side to speed this up a bit. This initial data list is retrieved only ONCE per login session.

              Queries are short and return summary results. Fetching an entire record of data is fairly quick since things are indexed on the back end.


              quote:

              I was trying to limit bandwith usage by downloading a copy of all the week's classes and then allowing the user to "save changes". I'm not too worried about getting a data collision since the classes are unique to each login.


              Sounds like your application protocol design is simple. User logs in and data is fetched by user id. User updates data and hits save. Done.

              In this scenario, if I'm right about your app, I'd still break this up into two different HttpService calls to obtain some sort of concurrent processing. One HttpService would be responsible for downloading data to populate pulldown boxes. The other to download the classes for that day.

              Actually, this begs the question; can the user update other day's than just the current? If so, it sounds like you'll have to allow the user to pick a day, fetch the data for that date, allow updates/save, then pick another day to update.

              In this scenario, the separation of HttpServices bears fruit, since the query to fetch semi-static data to populate combo boxes is only done once when the user initially logs in.

              Again, I'm not sure of your application design, so I'm just talking through different scenarios.

              quote:

              So there is no way to obtain the unique values from the dataset directly?


              I'm not sure I understand this question. You would obtain values to populate your combo boxes through an HttpService (for semi-static data). It may return something like:

              <dataList>
              ....<subjectList>
              ........<subject>english</subject><subject>spanish</subject><subject>spanglish</subject>
              ....</subjectList>
              ....<typeList>
              ........<type name="homework"/><type name="exam"/><type name="final"/>
              ....</typeList>
              </dataList>

              Then, you might have something like:

              <mx:ComboBox id="xxx" dataProvider="{dataListService.subjectList.subject}" selectedValue="{myDataService.lastResult.grade.subject.@name}" prompt=""/>


              Hope this helps.
              • 4. Re: XML - Get a list of possible values for filtering
                dmindler Level 1

                should have read:

                <mx:ComboBox id="xxx" dataProvider="{dataListService.subjectList.subject}" text="{myDataService.lastResult.grade.subject.@name}" prompt=""/>


                selectedValue= is part of our combobox custom component.
                • 5. Re: XML - Get a list of possible values for filtering
                  MacGyverMan Level 1
                  Thanks dmindler!

                  By finding the unique occurences inside an XML source, I meant to scan the supplied XML and find the uninque supplied values for the XML nodes, to populate the combo boxes. Somewhat like running a DISTINCT query via SQL.

                  I think I will separate the data to populate the controls as you suggest.

                  I was thinking that a user could update multiple days at once, allowing them to drag and drop contents from one day to the next, thus allowing them to copy content from one day to the next. I guess in that case, I'd need to query the DB on the drag and drop to make sure I'm not pasing redundant data.

                  Thanks for the info!

                  I think I was approaching this too much like a PHP problem initially. It's much easier to treat data in PHP than it is in Flex...at least for me it is.
                  • 6. Re: XML - Get a list of possible values for filtering
                    *gsb* Level 1
                    Late as usual I am, but if I understand your original post/need, I suggest that you dynamically make these data lists in Flex/AS3.

                    I have done this before as a series of filters, like:
                    Pick a winery, then an available year and finally a grape to see available stock. Or pick a grape and winery to see years are in stock.

                    Sure, these could be db queries, but the original XML dataset delivered to the application contains this data already.

                    So I prefer to dynamically build these "filter lists" on the fly.