3 Replies Latest reply on Nov 20, 2007 3:33 PM by ntsiii

    Creating a grid dynamically

    abstractionz
      Hello,

      I would like to bind a data grid to a soap response. The soap response defines the structure of the grid, i.e number of rows, columns, column names, etc. It looks something like this:

      <response>
      <rows>
      <rowheader>
      <column name="Company Name">
      <column name="Address">
      <column name="Phone">
      </rowheader>

      <row index="1">
      <CompanyName>ABC Company</CompanyName>
      <Address>123 Main Street</Address>
      <Phone>123 456 7890</Phone>
      </row>

      ....
      </rows>
      </response>

      The rowheader element defines the column names, and the rows element defines the rows, with the column values. How could I create a grid dynamically against a response like this? For this example response, it would create a grid with 3 columns - Company Name, Address, Phone - and 1 row.

        • 1. Re: Creating a grid dynamically
          atta707 Level 2
          Assuming that you've received the SOAP response and are ready to process the data to show in the grid:

          1) You would have a DataGrid somewhere in your application with an ID assigned to it.
          2) First you'll process rowheader stanza and instanciate DataGridColumn class for each column setting it's name and dataField properties.
          3) keep adding DataGridColumns to an Array
          4) assign this array to the columns property of the DataGrid
          5) now you'll start processing data rows; you'll use ArrayCollection or XMLCollection classes to add each row to the collection. The collection, obviously, would be [Bindable]
          6) Once you've all the rows in the collection you'll set this to the dataProvider property of the Grid, if no already set statically in the DataGrid tag.

          HTH.

          ATTA
          • 2. Re: Creating a grid dynamically
            abstractionz Level 1
            Thanks.

            Can the metadata also be read in dynamically? Perhaps from an attribute in the xml response.

            i.e Whether or not the column holds String vs. Numeric data?
            • 3. Re: Creating a grid dynamically
              ntsiii Level 3
              Yes, simply change ATTA's #2 to something like:
              2)Access the metadata node, loop over the column definition child nodes and instantiate a DataGridColumn for each ...

              If you want to see a simple exampl of dynamic columns, I have one on www.cflex.net, search for dynamic column. It uses the implicit structure of the data, not metadata, but the theory will be the same.

              Tracy