Announcement

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

    addRelatedUpdate resort?

    I have a listgrid which is correctly being updated using addRelatedUpdate() in the server-side.
    When I add a new record, it is added at the beginning of the list, in position 0. How can I add it at the "correct" position?
    Since I am in the server, I cannot just call listGrid.resort(). So how can I achieve this ?

    Using SmartGWT 4.1p, v9.1p_2014-09-25

    #2
    If you want an immediate resort, you will need to add client-side code that notices this response and acts on it, such as the callback to the call that adds the record, or a ResponseTransformer at the DataSource level. That could be based on it's data contents (related updates for a particular DataSource) or it could be based on a specific flag that you add via the server-side API dsResponse.setProperty().

    Comment


      #3
      Originally posted by Isomorphic View Post
      If you want an immediate resort, you will need to add client-side code that notices this response and acts on it, such as the callback to the call that adds the record, or a ResponseTransformer at the DataSource level. That could be based on it's data contents (related updates for a particular DataSource) or it could be based on a specific flag that you add via the server-side API dsResponse.setProperty().
      I tried with the following code:
      Code:
      setDataSource(DataSource.get("myDataSource", null, new ResponseTransformer() {
      			
      			@Override
      			protected void transformResponse(DSResponse response, DSRequest request,
      					Object data) {
      //here I will call lg.resort();
      			}
      		}));
      But the transformResponse() is not being called when being updated because of the addRelatedUpdate() method. It is only called from "normal" requests.
      Last edited by edulid; 27 Sep 2014, 06:07.

      Comment


        #4
        Right, transformResponse is expected to only be called for the primary DSResponse. So again you would need to either detect that the DSResponse has relatedUpdates that you want to trigger a resort(), or add an explicit flag on the DSResponse that you use as a trigger to cal resort().

        See also the docs for transformResponse - it wouldn't be valid to call resort() synchronously within that method, you should use a Scheduler delay (can be negligible time length).

        Comment


          #5
          Ok, thank you, I think I understand.

          But, in my use case, the component calling the update cannot possibly know if the row is going to be added or not.
          Please refer to my testcase here: http://forums.smartclient.com/showthread.php?t=31348. An update is done, and no one cannot possibly know if a record is going to be added to the list grid because of this update (both the component that calls the update and the server DMI cannot possibly know this, since they only execute an update: they do not know the records displayed in the listgrid).

          When the relatedUpdate() arrives at the listGrid, it (should) add a new record: ResultSet:isc_ResultSet_0 (created by: isc_ListGrid_0):updated cache: 1 row(s) added, 0 row(s) updated, 0 row(s) removed.

          But ONLY this listGrid can possibly know this, and I ONLY want to resort the listgrid when this happens.
          If only an update or a delete happens (at the listgrid level) , no resort should be done.

          So how to achieve this? Or am I misunderstanding something ?

          Comment


            #6
            First, if data unchanged, calling resort() won't change anything, so it's not clear why you'd try hard to avoid it.

            Second, grids aren't magic :) If you have some very critical reason why you need to know whether the record is in the dataset, just use grid.getResultSet().find(...) to see if it's there.

            Comment


              #7
              Originally posted by Isomorphic View Post
              First, if data unchanged, calling resort() won't change anything, so it's not clear why you'd try hard to avoid it.
              The listgrid has a very complex SQL, which needs some amount of time for execution. I just tested it, and every time I call resort(), the SQL is executed, since there are more than 75 rows in the dataset and the resort() is done at the server. So, each time, this complex SQL is executed, which is totally unnecessary for updates that don't insert anything into the listgrid (the update without resort() is SO FAST, which is SO NICE!!!). Also, we would waste a lot of bandwidth if we call resort() every time when a simple update occurs, since this resort() occurs at the server-side. That's why I only want to resort() when the update inserts something into the listGrid.

              Originally posted by Isomorphic View Post
              Second, grids aren't magic :) If you have some very critical reason why you need to know whether the record is in the dataset, just use grid.getResultSet().find(...) to see if it's there.
              Why magic? This information is already there:
              ResultSet:isc_ResultSet_0 (created by: isc_ListGrid_0):updated cache: 1 row(s) added, 0 row(s) updated, 0 row(s) removed.

              So you know that 1 row is being added (without magic ;-) ). I want to catch this exact situation, and call resort() there. But, as you explained earlier in this thread, I cannot call transformResponse for anything different than the primary DSResponse:
              Originally posted by Isomorphic View Post
              Right, transformResponse is expected to only be called for the primary DSResponse.
              You suggested 3 things:
              1) "either detect that the DSResponse has relatedUpdates that you want to trigger a resort() " -> How to detect this? Neither the calling component, nor the server, can possibly know that a record is going to be added to the listGrid. And, since I ONLY want to call resort() when a record is being added, I cannot do this.

              2) "could be based on a specific flag that you add via the server-side API dsResponse.setProperty()." -> Same thing here: we don't know at the server whether the record is going to be added to the listgrid, since the server doesn't know the listGrid's criteria.

              3) " If you have some very critical reason why you need to know whether the record is in the dataset, just use grid.getResultSet().find(...) to see if it's there" -> Where to call this? I don't have any method which is called when the relatedUpdate() arrives at the listGrid: you told me: "Right, transformResponse is expected to only be called for the primary DSResponse. ". So where to call grid.getResultSet().find(...)?
              In pseudocode I would need something like:
              Code:
              listgrid.addOnRelatedUpdateArrivedHandler( 
                 new RelatedUpdateArrivedHandler() {
                    @Override
                    relatedUpdateArrived(RelatedUpdateArrived e) {
                       if (e.insertedRecordToListgrid()) {
                          listgrid.resort();
                       }
                    }
                 });
              You wrote in another thread, that the record is added at the beginning of the listGrid by design:
              "1) this is by design, so that newly updated or added rows do not mysteriously disappear from the viewport when they are saved."
              Can't you have an option, so that when set, the added rows insert themselves "in place" regarding the sorting, instead of at the beginning of the listgrid? This option would be explicitely set. This would solve all the issues with resort(), since resort() would not have to be called any more.

              I hope I explained myself better and that you understand what I mean :-) Thanks for your patience
              Last edited by edulid; 30 Sep 2014, 12:52.

              Comment


                #8
                You've gotten quite confused, but you're missing something simple: you don't need transformResponse to be called for each individual related update, because in transformResponse(), you can simply access dsResponse.relatedUpdates to find out about the related updates.

                Those relatedUpdates have the data for the new records; you can check if those records are present in the ListGrid via ResultSet.find(), then call resort() only if they are actually present.

                Comment


                  #9
                  Originally posted by Isomorphic View Post
                  you can simply access dsResponse.relatedUpdates to find out about the related updates.
                  Ok, this sounds fine. But, am I blind or why don't I see any method at the CLIENT's DSResponse to getRelatedUpdates()?
                  In the server's DSResponse I have getRelatedUpdates() , but in the client's DSResponse I don't have anything similar... could you please double check if the API is missing?

                  Comment


                    #10
                    EDIT: After double checking: Ok, you are right, this may work :-)
                    But I still need the client's dsResponse.getRelatedUpdates() method ..
                    Last edited by edulid; 30 Sep 2014, 13:30. Reason: Double checked

                    Comment


                      #11
                      There isn't a specific dsResponse.getRelatedUpdates() method on the client, but any data from the dsResponse can be retrieved with getAttribute().

                      The suggestion was to install a single RequestTransformer at the DataSource level. Then you don't need code in every possible place where updates can occur.

                      If you prefer to do this somewhere more ListGrid-specific, there's also the DataChanged event on ResultSet, which would actually fire for every data update that actually affects that specific ListGrid. Note this would fire for adds and deletions too, but you could keep track of the ResultSet.getLength() to be able to tell the difference.

                      Comment


                        #12
                        Thanks, I think this will work. I will try it.

                        Comment

                        Working...
                        X