6 Replies Latest reply on Sep 9, 2010 7:05 AM by Flexicious-12vHYo

    Flex 4 datagrid paging AND filtering

    stpra123 Level 1

      I've got Flex 4, Zend and php. I've set up paging in my datagrid but how do I do server-side filtering? I have about millions of records so obviously can't do client side filtering...I've been googling all day w/ no luck. Anyone been able to do it or can point me to a tutorial?

        • 1. Re: Flex 4 datagrid paging AND filtering
          David_F57 Level 5

          hi,

           

          You need to create extra php service calls, the FB wizards are basically generating simple crud(create,read,update,delete) services its up to you to do the rest.

           

          for instance(this is very basic and not exactly what zendphp functions look like), the first function would be generated, the second you would create yourself.

           

          So programmatically you need to have an array with 2 values in it to pass in your service call (in the following case DOB).

           

          In flashbuilder itself you need to refresh your dataservice so it finds the new function, once that is done you need to edit the service call parameters to indicate what its return value is, becuase you have VO's already created by the wizard you can reuse the same ones, so the return used for the generated get all is the one you use for the 'filter' function.

           

          I have probably just confused you more now, but if you are struggling i will see if I can help with a step by step 'guide'. In the meantime have a look at this video it may help

           

          http://tv.adobe.com/watch/flash-camp-seattle/flash-builder-4-service-wizards

           

          function getClients ()

          {

          $mysql = mysql_connect($this->db_host, $this->db_user, $this->db_pwd);

          mysql_select_db( $this->db_name);

          $Query = "SELECT ID,Surname,Firstname,DOB from clients";

          $Result = mysql_query( $Query );

          while ($row = mysql_fetch_object($Result))

          {

          $ArrayOfClients[] = $row;

          }

          return( $ArrayOfClients );

          }

           

          function getSubsetClients($data)

          {

           

          $mysql = mysql_connect($this->db_host, $this->db_user, $this->db_pwd);

          mysql_select_db( $this->db_name);

          $Query = "SELECT ID,Surname,Firstname,DOB from clients Where DOB > $data.start and DOB < $data.end";

          $Result = mysql_query( $Query );

          while ($row = mysql_fetch_object($Result))

          {

          $ArrayOfClients[] = $row;

          }

          return( $ArrayOfClients );

          }

           

          • 2. Re: Flex 4 datagrid paging AND filtering
            stpra123 Level 1

            thanks. I've got the new php function but am confused by how you pass $data.start and $data.end from the flex app to the php (in my case, I have $searchThis)...similarly, I can't figure out where $startIndex and $numItems get defined. I've got the following in my php code:

             

            public function getFilteredPaged($searchThis, $startIndex, $numItems) {

             

            $stmt = mysqli_prepare($this->connection, "SELECT * FROM $this->tablename WHERE name=? LIMIT ?, ?");

            $this->throwExceptionOnError();

             

            mysqli_stmt_bind_param($stmt, 'ii', $searchThis, $startIndex, $numItems);

            mysqli_stmt_execute($stmt);

            $this->throwExceptionOnError();

             

            $rows = array();

             

            mysqli_stmt_bind_result($stmt, $row->name, $row->age);

             

                while (mysqli_stmt_fetch($stmt)) {

                  $rows[] = $row;

                  $row = new stdClass();

                  mysqli_stmt_bind_result($stmt, $row->name, $row->age);

                }

             

            mysqli_stmt_free_result($stmt);

            mysqli_close($this->connection);

             

            return $rows;

            }

            • 3. Re: Flex 4 datagrid paging AND filtering
              David_F57 Level 5

              hi,

               

              Can you message me as it would be easier to go over this in a connect session...

               

               

              David.

              • 4. Re: Flex 4 datagrid paging AND filtering
                David_F57 Level 5

                hi,

                 

                This may be the cuase of some of your problems

                 

                mysqli_stmt_bind_param($stmt, 'ii', $searchThis, $startIndex, $numItems);

                 

                it should be

                 

                mysqli_stmt_bind_param($stmt, 'sii', $searchThis, $startIndex, $numItems);

                 

                David.

                • 5. Re: Flex 4 datagrid paging AND filtering
                  stpra123 Level 1

                  I've rebuilt the project and solved the problem. I must have had the callresponder set up wrong. You saved me a lot of time on getting the php part set up. thx!

                  • 6. Re: Flex 4 datagrid paging AND filtering
                    Flexicious-12vHYo

                    Have you looked at our product, http://www.flexicious.com? This provides built in UI for paging and filtering.