7 Replies Latest reply: May 13, 2011 5:31 AM by ecommerce web solutions RSS

    CFGRID binding CFSELECT and Cookie

    Clay Hess Community Member

      I an just dipping my toes into the CF8 AJAX tags and am having a blast. I have run into an issue that I need assistance on though. If this has been already answered by another post, I cannot find it. So if there is one, please point me in the right direction.


      Here is my issue...


      I have an order form and am using a CFGRID to show order history. [Note:this is not a typical ecommerce order form. It is a way for my customer, who provides products to non-profits a way they can place their orders online, but no cc processing]. Anyway, I have a cfselect that is a list of the organizations that use this site. They select their organization, which populates the db upon submission for ease of processing orders, but also sets a cookie so the customer does not have to redo the cfselect everytime since they are inputting lots of orders at once.


      So, I have a CFGRID so they can see all of their orders that have been placed to date. I used the bind attribute to bind my cfgrid to the cfselect, which in turn pulls query data from a cfc. The problem I am running into is that when the page loads and the cfselect gets the proper value selected based upon the cookie, the cfgrid does not seem to pick that up and populate with the correct query information. It only populates when the cfselect is changed. I am thinking that this has to do with server side versus client side processing, but have not been able to figure out a way around the issue.


      Any help is appreciated.


      Here is my code...



      <cfcomponent displayname="orders" hint="CFC for retrieving data from orders db">
      <!---This function retrieves all orders from the db based upon where parameter (organization)--->
      <cffunction name="getOrders" access="remote" returntype="struct" hint="returns all orders for a specific organization/customer">
              <cfargument name="page" required="true" />
              <cfargument name="pageSize" required="true" />
              <cfargument name="gridsortcolumn" required="true" />
              <cfargument name="gridsortdirection" required="true" />
              <cfargument name="organization" type="string" required="true" />
              <cfif gridsortcolumn EQ "DATEORDERED">
               <cfset gridsortcolumn = "ORDERSIGNUPDATE">
              <cfquery name="rsOrgOrders" datasource="BadgerWreathOrders">
                  FROM Orders
                  WHERE ORDERORGANIZATION = '#organization#'
                  <cfif gridsortcolumn NEQ ''>
                  ORDER BY #gridsortcolumn# #gridsortdirection#
        <cfreturn queryconvertforgrid(rsOrgOrders,page,pageSize)>



          <cfgrid name="orderGrid" bindonload="yes" colheaderbold="Yes" font="Verdana, Geneva, sans-serif" fontsize="9px" label="true" striperows="yes" striperowcolor="##CCCCCC" selectcolor="##00CC66" rowHeaders="No" format="html" bind="cfc:cfc.orders.getOrders({cfgridpage},{cfgridpagesize},{cfgridsortcolumn},{cfgridso rtdirection},{organization})" pageSize="10" preservepageonsort="true" selectmode="single" selectonload="false" bgcolor="##F4FFE4" colheaderfontsize="9px">
              <!--- cfgridcolumn tags arrange the table and control the display. --->
              <!--- Hide the primary key, required for update --->
              <cfgridcolumn name="ORDERID" display="No" />
              <cfgridcolumn name="ORDERFIRSTNAME" header="First Name" Select="No" width="65" />
              <cfgridcolumn name="ORDERLASTNAME" header="Last Name" Select="No" width="65" />
              <cfgridcolumn name="ORDERADDRESS1" header="Address 1" width="105" />
              <cfgridcolumn name="ORDERADDRESS2" header="Address 2" width="60" />
              <cfgridcolumn name="ORDERCITY" header="City" width="55" />
              <cfgridcolumn name="ORDERSTATE" header="State" width="35" />
              <cfgridcolumn name="ORDERZIP" header="Zip" width="30" />
              <cfgridcolumn name="DATEORDERED" header="Order Date" width="65" />


                    <cfselect name="organization" id="organization" onBlur="WA_setCookie(WA_CookieObj,'badgerorderorg',document.ecart_checkout_form.organizat ion.value,true,0,30)">
                    <option value="none" selected="selected">Please select your organization</option>             
                    <option value="Cornerstone Christian School">Cornerstone Christian School</option>             
                    <option value="Faith Christian Academy">Faith Christian Academy</option>             
                    <option value="Knute Rockne Memorial Kiwanis Club of Granger">Knute Rockne Memorial Kiwanis Club of Granger</option>             

      Thanks in advance


        • 1. Re: CFGRID binding CFSELECT and Cookie
          Clay Hess Community Member

          I believe I figured out how to do this. I thought I would post my solution here in case someone else runs into this issue. If there is a better way, let me know..


          What I did was utilize a CFIF statement within my CFC to check for the existence of the cookie and change my WHERE statement accordingly. This should then populate the CFGRID with the appropriate data.


                      <cfif IsDefined('cookie.BADGERORDERORG') and cookie.BADGERORDERORG NEQ ''>
                       WHERE ORDERORGANIZATION = '#cookie.BADGERORDERORG#'
                       WHERE ORDERORGANIZATION = '#organization#'

          Again, if anyone has any other thoughts, I would be glad to hear them.





          • 2. Re: CFGRID binding CFSELECT and Cookie
            BKBK CommunityMVP

            Did you experiment in the cfselect with onChange in place of onBlur?

            • 3. Re: CFGRID binding CFSELECT and Cookie
              Clay Hess Community Member

              No I did not

              • 4. Re: CFGRID binding CFSELECT and Cookie
                BKBK CommunityMVP

                You could.

                • 5. Re: CFGRID binding CFSELECT and Cookie

                  Hello, I'm new on here and excited to be part of the group, Really you have shared great resources for everyone.

                  • 6. Re: CFGRID binding CFSELECT and Cookie
                    cfwild Community Member

                    HI Clay,


                    Just a thought:


                    If the organization uses a login (I'm assuming that they are), why not set a SESSION variable equal to what you would use in a SQL WHERE clause.  That way, when you take them to the cfgrid, just use their SESSION variable in the cfc query.


                    Let's say that the organization is Faith Christian.  When they login you set SESSION.ORDERORGANIZATION = 'Faith Christian'. So in your cfc, you would have:


                    <cfquery name="rsOrgOrders" datasource="BadgerWreathOrders">
                                FROM Orders
                                <cfif gridsortcolumn NEQ ''>
                                ORDER BY #gridsortcolumn# #gridsortdirection#


                    This would completely eliminate the cfselect and its bind to the cfgrid.  Just thinking on how to make your life a bit easier with a lot less code.


                    I don't play with cookies much, but you could probably do the same thing with a cooke variable as opposed to a session variable.