4 Replies Latest reply on Feb 23, 2007 12:10 AM by Like2Flex

    Problem with Query and DataGrid

    Like2Flex Level 1
      Hello,

      Am having a problem to display my query data into a datagrid.

      My query is as such :
      select D,B,A,C from tbl_test

      In flex :

      Note that I managed to get the selected fields from the query in a comma delimited list as such "(D,B,A,C)"

      Now I want to loop trhough the list, and display each columns with its data in my datagrid.
      I DON'T want to use : my_grid.DataProvider = myqueryresult

      I definitely need to loop and then display the data.

      I have reached a certain stage (see below).

      var params:Array = listtest.split(",");
      for(var i: int = 0; i < params.length; i++){
      Alert.show(new String(params ));
      Whats in here??
      }

      Anyone can help me with this issue please ??

        • 1. Re: Problem with Query and DataGrid
          michael_ramirez44 Level 1
          Are you wanting to add columns dynamically?

          var columns:Array = new Array();
          var params:Array = listtest.split(",");
          for(var i: int = 0; i < params.length; i++){
          Alert.show(new String(params));

          var col:DataGridColumn = new DataGridColumn(new String(params) )
          col.dataField = "someProperty";
          columns.push( col);


          }

          dg.columns = columns;
          • 2. Re: Problem with Query and DataGrid
            Like2Flex Level 1
            Hello I changed the line below :

            col.dataField = "someProperty";

            to

            col.dataField = ords.getItemAt(0).params ; //Note that there is i near params

            But I dont get all the items in my list alerted.
            But when i remove the line above from my code, all items in my list are alerted.
            I don't understand this point.

            Note that "ords" is my ArrayCollection which gets data from my cfc.

            Pls help me out.
            Thx
            • 3. Re: Problem with Query and DataGrid
              michael_ramirez44 Level 1
              var columns:Array = new Array();
              var params:Array = listtest.split(",");
              for(var i: int = 0; i < params.length; i++){
              Alert.show(new String(i));

              var col:DataGridColumn = new DataGridColumn(new String( i ) )
              col.dataField = i;
              columns.push( col);

              }

              dg.columns = columns;
              • 4. Re: Problem with Query and DataGrid
                Like2Flex Level 1
                Well am getting the headers now (headersa are the values of i)

                But I still can't populate my datagrid. Note that in my .cfc I have a function "getOrds" which has a query which returns the query.

                so in flex I do:
                public function getOrds(event:ResultEvent):void
                {
                ords = event.result as ArrayCollection;
                //grd_orders.dataProvider = ords; // Normally if I do this line it gives populates the grid, but I can't use this because I want my columns to be in a particular order, which I have in the list.

                //Alert.show(new String(listtest));

                var columns:Array=new Array();
                var params:Array = listtest.split(",");

                for(var i: int = 0; i < params.length; i++){

                var col:DataGridColumn = new DataGridColumn(new String(params ));
                col.dataField = ords.getItemAt(0).i; or col.dataField = i [THIS DOES NOT POPULATE THE GRID :( ]

                columns.push(col);
                grd_ords.columns = columns;

                }

                }

                Any help again on this issue.

                Thx