16 Replies Latest reply on Feb 26, 2007 5:00 AM by Like2Flex

    Server IP Address & Datagrid vs. data provider

    Cédriic Level 1
      I have two questions which are not at all related to each other.

      1. Is there a method/way to get automatically the IP address of the server the application is coming from ?

      2. How is it possible to prevent a datagrid to sort the columns themselves according to the column names ? I have a data provider which is linked to a datagrid but I don't know in advance what is inside. However, I want the colums to be in the same order as specified in the data provider.
      For example :
      my data provider contains the following column names : B, C, F, A, D, E
      my datagrid displays : A, B, C, D, E, F

      Thanks in advance for your answers ! ;)
        • 1. Re: Server IP Address & Datagrid vs. data provider
          rkschulz Level 1
          Re 2) Can't you specify the columns any which way you like?

          <mx:DataGrid ...
          <mx:columns>
          <mx:DataGridColumn ...
          <mx:DataGridColumn ...

          Maybe I don't get the question.

          Robert.
          • 2. Re: Server IP Address &amp; Datagrid vs. data provider
            Cheree Singal Level 1
            Are the columns static? If not, may be this helps:

            [Bindable]
            public var array: Array;
            public function createDG(): void{
            array = [new DataGridColumn('Id'),new DataGridColumn('Product')];
            var dataPro: Array = [{Id: '1',Product: 'fs'},{Id: '2',Product: 'sr'},{Id: '2',Product: 'sr'}];
            testDG.dataProvider = dataPro;

            }

            Now, create the data grid whose columns will be provided by 'array'.

            <mx:DataGrid id="testDG" columns="{array}" creationComplete="createDG/>

            May be this wud help:)

            Cheree
            • 3. Re: Server IP Address &amp; Datagrid vs. data provider
              Cédriic Level 1
              Thanks Cheree. This is exactly what I need for my purpose !

              Mmmm ... Anyone to answer my 1st question, please ? ;)
              • 4. Re: Server IP Address &amp; Datagrid vs. data provider
                Like2Flex Level 1
                Hello,

                The line below :

                var dataPro: Array = [{Id: '1',Product: 'fs'},{Id: '2',Product: 'sr'},{Id: '2',Product: 'sr'}];


                Does it mean that for each row of the datagrid, I have to specify for each row, the values. Here in your example,I think you have 3 rows. its a prob if I have to specify each row in the above code, because I have thousands of rows !.

                your idea pls??

                thx
                • 5. Re: Server IP Address &amp; Datagrid vs. data provider
                  Cheree Singal Level 1
                  Hi Cédriic,
                  No, the code I gave here was just an example. In real scenario, u wud get the data for the rows of data grid in the form of a list of objects, say, an ArrayCollection. In that case, u will make that arrayCollection the dataProvider of the data grid.
                  But the point to be noted is that u may have to pass a map of the properties in arrayCollection with their display names that wud be displayed as headers in data grid columns. e.g.
                  The map objects may look like this(for the example I gave u):
                  {fieldName: "prod", displayName: "Product"}
                  {fieldName: "a", displayName: "A"}
                  Here fieldName are the names of attributes present in the dataProvider arrayCollection.


                  Then let dGColumns be array of columns of data grid & dataNameMap be the list of the map objects.
                  Create the column of grid as follows:

                  public function createDG(): void{
                  var dGColumns : ArrayCollection = new ArrayCollection(new Array());
                  for(var i: int = 0; i<dataNameMap.length; i++){
                  var dgCol: DataGridColumn = new DataGridColumn(dataNameMap .displayName);
                  dgCol.dataField = dataNameMap
                  .fieldName;
                  dGColumns.addItem(dgCol);
                  }
                  }
                  Now data grid will look like:

                  <mx:DataGrid id="testDG" columns="{dGColumns}" creationComplete="createDG()"/>

                  Hope I dint confuse u :)
                  I haven't tried this piece of code but hopefully this will work.

                  Cheree
                  • 6. Re: Server IP Address &amp; Datagrid vs. data provider
                    Cheree Singal Level 1
                    Oops, I gave i within square barckets to show indexing of array, but it made everything italicized. I dont know how to escape it. Plz see that indexing is to be done for dataNameMap while creating dGCol!
                    • 7. Re: Server IP Address &amp; Datagrid vs. data provider
                      Like2Flex Level 1
                      Heelo Cheree,

                      I badly need your help.

                      I modified the codes as follows, and the function createDG() is working, I tested it and am getting "listtest" which is the list of fields I have choosen in the query (note that list is comma delimited, thats why am using the split function

                      public var listtest:String =new String();
                      public var dGColumns : Array= new Array();

                      public function createDG(): void{
                      myService.getProfileDefinedFieldsforSearch(varprofile_idSearch);
                      Alert.show(new String(listtest));

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

                      for(var i: int = 0; i< params.length; i++){
                      Alert.show(new String(params ));
                      var dgCol: DataGridColumn = new DataGridColumn(params
                      );
                      dgCol.dataField = params.fieldName;
                      dGColumns.addItem(dgCol);
                      }
                      }

                      And my datagrid, is as such.

                      <mx:DataGrid id="testDG" columns="{dGColumns}" creationComplete="createDG()"/>

                      But am getting this error :
                      Data Binding will not be able to detect assignments to "dGCOlumns".


                      Can you please tell me what I am doing wrong?

                      Thx
                      • 8. Re: Server IP Address &amp; Datagrid vs. data provider
                        Cheree Singal Level 1
                        Hi,

                        No need to worry my friend:-)

                        Try giving:

                        [Bindable]
                        public var dGColumns : Array= new Array();

                        If this doesnt work, use an array collection instead of array.
                        Let me know if u still face the problem.

                        Cheree
                        • 9. Re: Server IP Address &amp; Datagrid vs. data provider
                          Like2Flex Level 1

                          Hello, I have put:
                          [Bindable ]
                          public var dGColumns:Array= new Array();

                          I still get the same error.

                          Let me explain to you the whole stuff.

                          I have a .cfc which has a function called "getOrds()". This function consists of a simple select statement (select B,C,A,D from mytable).


                          Now in flex, I have a function called getOrds(),see below. This function was previously being used to populate my datagrid, but the columns were not in the desired order.

                          public function getOrds(event:ResultEvent):void
                          {
                          ords = event.result as ArrayCollection;
                          grd_ords.dataProvider = ords;
                          }


                          So I create the new function "createDG()" which you suggested, as follows :
                          Note that myService.getProfile is in fact the function which allows me to get the list of columns in the desired order. So I get "listtest" which is my comma delimited list of columns to be displayed in the grid.

                          public function createDG(): void{
                          myService.getProfile(id);
                          Alert.show(new String(listtest));

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

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

                          var dgCol: DataGridColumn = new DataGridColumn(params
                          );
                          dgCol.dataField = params .fieldName;
                          dGColumns.addItem(dgCol);
                          }
                          }

                          And my datagrid is as follows :
                          <mx:DataGrid horizontalScrollPolicy="auto" id="grd_orders" columns="{dGColumns}" creationComplete="createDG()">

                          It is on the above line that am getting the error, I previously mentioned.

                          I also tried :
                          public var dGColumns : ArrayCollection = new ArrayCollection();

                          Here as well, I get another error :
                          Implicit coercion of a value of type mx.collections:ArrayCollections to an unrelated type Array.


                          Am I missing anything ?
                          Is my function well established to populate the grid ?

                          I need your precious help my friend. Thks and regards.
                          • 10. Re: Server IP Address &amp; Datagrid vs. data provider
                            Like2Flex Level 1
                            I am trying this since 3 days but in vain.

                            Is it possible for you to let me have a look at your sample code (I mean your cfc + flex codes) fi you don't mind because am quite worrying about this issue now :(

                            Pls help.
                            • 11. Re: Server IP Address &amp; Datagrid vs. data provider
                              Cheree Singal Level 1
                              Hi,
                              I was out yesterday. So, cud not reply.
                              Unfortunately, I have never workrd with cfc. So, I dont have any code to show.
                              Let me think about the problem.I ll get back in a short while.

                              Cheree
                              • 12. Re: Server IP Address &amp; Datagrid vs. data provider
                                Like2Flex Level 1
                                ok cheree...waiting impatiently for your solution.
                                thx
                                • 13. Re: Server IP Address &amp; Datagrid vs. data provider
                                  Cheree Singal Level 1
                                  Hi,
                                  Plz clarify whether u r getting an error or a warning? Although I have not tried your code, but I have seen such warnings before that disappear when I give [Bindable]. But in my case, its always an ArrayCollection. Have you tried using that?

                                  Cheree
                                  • 14. Re: Server IP Address &amp; Datagrid vs. data provider
                                    Like2Flex Level 1
                                    When am using Array,I get this "warning"

                                    -> Data Binding will not be able to detect assignments to "dGCOlumns".

                                    I also tried ArrayCollection as well but here I get an "error"
                                    -> Implicit coercion of a value of type mx.collections:ArrayCollections to an unrelated type Array.

                                    I have used bindable... but the error still persists.

                                    Maybe if you have time, please try my code and see if it executes correctly on you side.

                                    regards




                                    • 15. Re: Server IP Address &amp; Datagrid vs. data provider
                                      Cheree Singal Level 1
                                      That "error" is quite expected as 'columns' has to be an array. Try this:

                                      [Bindable]
                                      public var dGColumns : ArrayCollection = new ArrayCollection();
                                      ...

                                      <mx:DataGrid id="testDG" columns="{dGColumns.toArray()}" creationComplete="createDG()"/>

                                      Cheree
                                      • 16. Re: Server IP Address &amp; Datagrid vs. data provider
                                        Like2Flex Level 1
                                        Wow... this does the job !!

                                        Thanks a lot buddy.

                                        You have been of great help.

                                        God bless you !!