Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    How to add an extra field to datasource

    Hi there,

    i m trying to use a ListGrid to display data in a table, there's one field is calculated by COUNT(*) in the SQL. The data loaded alright when the ListGrid starts up, but when the ListGrid is updated, the count number disappears. i guess the ListGrid re loads the data for the updated row using the default 'fetch', is there any way that i can add this extra field to the datasource so it can always be displayed as a part of the data?

    Thanks!

    #2
    Yes, you can either:

    1. Omit an operationID on the "fetch" operationBinding, so it becomes the default fetch operation, called whenever cache updates need to happen

    OR

    2. Create an operationBinding for the "update" operationType and set operationBinding.cacheSynchOperation to the operationId of your custom fetch operation

    Comment


      #3
      Thanks for the quick reply.

      I actually have tried the first way, but overriding default fetch comes with a problem, because the SQL needs a criteria -- ('parent_company', '3'), when the grid updates and refreshes the updated row, the query was executed without the criteria, hence reported error. Any way to avoid this?

      The second method looks better, it seems that i can use customized update and fetch, i'll give it a shot.

      Thanks!

      Comment


        #4
        Sorry dude, i still have to ask for help.

        I tried the second way to create a update operationBinding, and point the cacheSyncOperation to my fetch function, but as the fetch uses extra criteria for the query, it shows an error after the update. Please see the configurations below:

        Code:
        <operationBinding operationType="fetch" operationId="get_pods_with_pages" customValueFields="pages" requreAuthentication="true">
        			<selectClause>
        				*, COUNT(*) AS pages
        			</selectClause>
        			<tableClause>
        				gxpod_pod
        			</tableClause>
        			<whereClause>
        				parent_carrier = [b]$criteria.parent_carrier[/b]
        				AND status = $criteria.status
        			</whereClause>
        			<groupClause>
        				primary_datacell
        			</groupClause>
        		</operationBinding>
        		
        		<operationBinding operationType="update" operationId="update_primary_datacell_and_refresh_with_pages" cacheSyncOperation="get_pods_with_pages">
        			<tableClause>
        				gxpod_pod
        			</tableClause>
        			<valuesClause>
        				$defaultValuesClause
        			</valuesClause>
        			<whereClause>
        				$defaultWhereClause
        			</whereClause>
        		</operationBinding>
        The bold part, $criteria.parent_carrier takes a value when run the query, but obviously the update doesn't pass the value through to fetch query, could you show me how to do this?

        Thanks!

        Comment


          #5
          Sorry please ignore my previous post, i modified the query and now it works great


          It would be great if you could advise if this is the right way to do it. Thanks
          Code:
          <operationBinding operationType="fetch" operationId="get_pods_with_pages" customValueFields="pages" requreAuthentication="true">
          			<selectClause>
          				*, COUNT(*) AS pages
          			</selectClause>
          			<tableClause>
          				gxpod_pod
          			</tableClause>
          			<whereClause>
          				$defaultWhereClause
          				#if($criteria.parent_carrier)
          				AND parent_carrier = $criteria.parent_carrier
          				#end
          				#if($criteria.status)
          				AND status = $criteria.status
          				#end
          			</whereClause>
          			<groupClause>
          				primary_datacell
          			</groupClause>
          		</operationBinding>

          Comment


            #6
            Hi liudi,

            you could look at this option if you are using 4.1d (I didn't try, yet): "Declarative Grouping and Sums"
            http://blog.isomorphic.com/new-smart...-9-1-features/

            For the <selectClause>: You could omit it if you put your COUNT(*) as customSelectExpression for DS-field pages. I think the <tableClause> can be omitted as well, but I'm not sure here.
            The $defaultWhereClause should better be ($defaultWhereClause).
            requreAuthentication has a typo.

            Best regards,
            Blama

            Comment

            Working...
            X