Announcement

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

    Possible to have a ListGrid field be client-side only?

    Hello friends,

    Is it possible to have a ListGrid field be client-side only?

    I would like to have a ListGrid be client/server for most fields but have one field be programmatically filled from the client's logic only. (for very frequent & efficient updating without client/server roundtrips)

    I am thinking of doing this by creating a DSResponse object as an UPDATE, filling in the field I need with its value and updating the related datasource via updateCaches()

    Is there a better way to do it?

    Many thanks!

    Jean-Pierre

    #2
    That's overkill, just use DataSource.transformResponse() to modify the data after it comes back from the server, adding your additional field there.

    Comment


      #3
      Hi Admin, thanks for the hint in the right direction.

      I am hoping to update this field several times per second and hope to make this as efficiently as possible with no flicker. Thus far, if I update an individual row several times a second, the grid row flickers and a fair amound of bandwidth is consumed.

      The idea was to update this frequent value with Comet server push and just update that one field without the normal overhead. In other words, for maximum efficiency, I need to update a field's value out of the flow of normal updates... outside the execution flow related to transformResponse().

      Given the above requirements, would the 'updateCaches()' approach be the best approach?

      Jean-Pierre

      Comment


        #4
        Yes, it's the best approach for the described use case - didn't we already go over this with you? - and it neither introduces flicker or uses any bandwidth - if you're seeing flicker or bandwidth consumption it may be something like repeated image fetches due to incorrectly set caching settings.

        Comment


          #5
          Hi Admin, thanks again for confirming this solution.

          For the flicker, it appears that only the slider I insert via createRecordComponent() flickers during repeated updates... I'm not sure if it will go away if I just change one field and not the field for that flicker, but will try.

          As per my previous need, it was to update the entire row when that row changed on the server (a few times a minutes), while this need is to update a single field with high efficiency possibly several times per seconds.

          The reason I asked is that by analysing the RPC calls and looking into what is serialized for DSRequest and DSResponse, there is a lot of textual info that consumes bandwidth and client/server MIPS when I only really need to push one integer via Comet to update this frequently changed field, hence this new set of requirements.

          For this second need, I think when that small Comet packet comes in, the approach with updateCaches() is optimal one, no?

          Thanks again!

          Jean-Pierre

          Comment


            #6
            Um, yes, as we keep saying and as the docs for updateCaches() explicitly state, it is designed for this use case (real-time updates via HTTP streaming).

            You seem to have asked essentially the same question several times now. If there's a specific concern, try to be very specific with the question.

            Comment


              #7
              Hi Admin, thanks for precisions...

              The original question was to determine if a given field described in a ds.xml could be somehow separated from the normal dsRequest/dsResponse call flow for overriding behavior on the client.

              Fortunately, as the server appears to safely ignore this out-of-band field with just a warning, overriding client-side behavior with updateCaches() will work and that's great!

              I just wanted to see if there was a way to separate a field for client-side only processing but this solution is fine too.

              Thanks again!

              Jean-Pierre

              Comment


                #8
                Hi all,

                For those following this thread, the following documented code enables client-side logic to update any field of any row without invoking the server. (This could be useful for rapidly updating fields via HTTP streaming)

                Note that, any normal client-server round-trip that updates rows you update via this client-side technique will of course overwrite the values you push here without warning!

                Code:
                    public ListGridRecord FindListGridRecord(ListGrid oGrid, String sFieldName, String sFieldValue) {
                        // Returns the ListGridRecord from oGrid having 'sFieldName' set to 'sFieldValue'
                        //***WEAK: Assuming the criteria will only return one record!
                        //***TODO!!: SmartGWT 2.5 will likely have a better native function to replace this call
                
                        Record oRecord = oGrid.getResultSet().find(sFieldName, sFieldValue);        //***LEARN: How to find a ListGridRecord by primary id as per technique at http://forums.smartclient.com/showthread.php?t=16988&page=2
                        ListGridRecord oRec = new ListGridRecord(oRecord.getJsObj());
                        return oRec;
                    }
                    public void UpdateGridField_ClientSide(ListGrid oGrid, String sKeyName, String sKeyValue, String sFieldName, String sFieldValue) {
                        // Advanced client-side function that updates field 'sFieldName' to 'sFieldValue' for grid record with primary key 'sKeyName' to 'sKeyValue' directly without the normal client/server round trip
                        // (Function is useful for rapidly changing a ListGrid record normally attached to a server datasource wihout the server round-trip.)
                        // (Used upon receiving Comet message that a frequently changed field has changed)
                        //***WARN: Note that future server updates to this row will overwrite the value we push in here!
                
                        ListGridRecord oRec = FindListGridRecord(oGrid, sKeyName, sKeyValue);       // Obtain the existing data already in the grid's cache for this row
                        if (oRec == null)           //***TODO: logging!
                            return;
                
                        DSRequest oDSReq = new DSRequest();                             // Create a nearly-blank DSRequest object that will tell updataCaches() below we just need to update what we pass into via oDSResp
                        oDSReq.setOperationType(DSOperationType.UPDATE);
                
                        DSResponse oDSResp = new DSResponse();                          // Form a DSResponse with only one record to update
                        Record[] aRec = new Record[1];
                        oRec.setAttribute(sFieldName, sFieldValue);                     // Change the value of the requested field
                        aRec[0] = oRec;
                        oDSResp.setData(aRec);
                
                        oGrid.getDataSource().updateCaches(oDSResp, oDSReq);            // Ask the datasource to update its cache.  This will automatically update the UI of all GUI components linked to this datasource
                    }

                Jean-Pierre

                Comment

                Working...
                X