Announcement

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

    #31
    Hi Blama

    Thanks for taking the time to send me a (possible) solution.

    At the moment I always perform a SQL COUNT (this is the first command I give). If it returns 0, I don't need to do the actual record fetching. I'm fine for now with a SQL COUNT. That most likely means I won't need that "notEqual -1" criterion.

    The idea of sending back the total number of records in the first data object is brilliant! I will take a look into that right away. And in case I don't have data, that automatically means myTotalRows is 0. :-)

    You mentioned addDataArrivedHander() which most likely is a SmartGWT thing, but I think I can use dataArrived().

    Again, thanks for your reply!
    Last edited by wallytax; 13 Sep 2024, 04:40.

    Comment


      #32
      Hi Blama , so far no success (yet). My main concern is how to retrieve the actual record containing that extra information. Could you give me a hint of what that dataArrived() handler looks like?

      Comment


        #33
        Originally posted by claudiobosticco View Post

        sorry, I misunderstood the sentence in the QuickStart Guide "you can override DataSource.transformRequest() and DataSource.transformResponse() and add Java code to handle those cases", and I thought that "and add Java code" was also referred to the transformRequest.
        That's a typo, it should say JavaScript. Too much sharing between the SmartGWT and SmartClient QuickStart Guides in this case! We'll get it fixed.

        Comment


          #34
          Originally posted by wallytax View Post
          Hi Blama , so far no success (yet). My main concern is how to retrieve the actual record containing that extra information. Could you give me a hint of what that dataArrived() handler looks like?
          Not really, as I use SmartGWT, but it will be something along the lines of:
          Code:
          dataArrived : function (startRow, endRow) {      
              for (Record r : this.data.getRange(startRow, endRow)) { // or getAllCachedRows()?
                        if (r.myCustomRowCount) {
                               mylabel.setContents("We have " + myCustomRowCount + " records");
                               break;
                       }
              }
          });
          It is important to have a field myCustomRowCount in your datasource, as it wont be in the data otherwise, I think.

          Best regards
          Blama

          Comment


            #35
            Originally posted by Blama View Post
            It is important to have a field myCustomRowCount in your datasource, as it wont be in the data otherwise, I think.
            unless you have dropExtraFields=false

            Comment


              #36
              We're not sure why a second approach is being considered here, since there is already a solution that simply stashes the property on the component, or elsewhere. We would not recommend adding a field to the DataSource for this, as that would place it in every record and/or require iterating over all records on the server to add the property.

              It would also require adding this field to every DataSource, and simply put, it's not a field of the record, it's a field of the overall response, like totalRows.

              So we would recommend returning to having the row count as a property of the overall response, which is also how it's implemented in 14.0, meaning you will be able to use the new 14.0 features immediately by just renaming your property to match and deleting your extra code.

              Comment


                #37
                So far, there is NO solution for this particular situation.

                1) Have the server return the "estimatedTotalRows" in combination with "progressiveLoading": true as suggested in version 14 doesn't work with the latest snapshot (at the moment of writing 2024-09-15). In an earlier post I've already mentioned I've looked into version 14 for just a couple minutes after a suggestion from Isomorphic. At least, I don't see a way of retrieving the "estimatedTotalRows" in events like dataArrived() or dataChanged().
                2) Copying the property over in transformResponse() to the response variable in the data source doesn't work either: not accessible from the grid's dataArrived() or dataChanged() events.
                3) Copying the property over to the component self in transformResponse() seems to work but a post from Isomorphic suggests this means the row count must also be returned in non-fetch operations, which is unwanted.

                I've dropped every attempt, because it simply costs way too much time and reverted back to the original implementation which only causes a warning in the browser's developer console.

                Comment


                  #38
                  3) Copying the property over to the component self in transformResponse() seems to work but a post from Isomorphic suggests this means the row count must also be returned in non-fetch operations, which is unwanted.
                  No, we said that your logic assumes that the estimated rows are returned every time. You simply need to adjust your logic with a null check.

                  And also the whole problem is avoided if you just call fetchData(), or via myriad other ways.

                  In a nutshell: this is a very simple and routine problem, with a solution explained in the QuickStart Guide, which works.

                  Comment


                    #39
                    Okay, so I would simply need to check in the dataChanged() handler if response.estimatedTotalRows != null? That would be an easy fix.

                    I would prefer calling fetchData() if that gives me access to the response (which should be the case). But in this solution, I would need to disable autoFetchData? If so, where would I place the initial fetchData() that mimics the autoFetchData()?

                    Comment


                      #40
                      Choosing a solution has consequences for other things. As an example the "auto fetch data". Simply saying I should use fetchData() is - IMHO - not enough, because that has consequences for that auto fetching: I need to know where to put the initial fetchData() and most likely keep track of it being called for the first time. More or less rebuilding the auto fetch behavior and that feels uncomfortable.

                      Comment


                        #41
                        wallytax, this is an extremely simple situation, well described in the QuickStart Guide, which requires you to write one line of logic.

                        Unfortunately, in that one line of logic you are required to write, you made an elementary programming mistake, which we helpfully pointed out - it's just the lack of a null check.

                        That's literally it.

                        Specifically, as we said in post #25, your transformResponse() logic just has a simple flaw - it needs a null check. Otherwise, your own code assumes that every single one of your server's responses on that DataSource has that custom property. And whether it is present or not, it's going to overwrite the property you are trying to set on your component.

                        This is not a framework requirement, not a framework flaw. It is a simple logic bug in your override method, which we pointed out for you.

                        Correct the bug in your own code and you will be fine. You will have implemented the simple solution that was explained in the QuickStart, and then here, multiple times.

                        There is no need to switch between autoFetchData and fetchData(), even though that is extremely trivial - it's just not relevant.

                        You literally just need a simple null check in the one line of code that the system requires you to write. That's it.

                        Comment


                          #42
                          Thanks for the clear explanation! I will implement it like that!

                          Comment


                            #43
                            This was 42 posts to get to a very basic result, where the approach is covered in the QuickStart Guide and just a single line of actual logic is required. This keeps happening with your threads.

                            We have previously asked that you make better use of ChatGPT to avoid this severe drain on community resources.

                            .Just a note that ChatGPT gets the approach exactly correct on the first try:

                            https://chatgpt.com/share/66e8834d-c...c-22b0990c6168

                            Prompt: "I'm using Isomorphic SmartClient with a RestDataSource and a backend based on Ruby on Rails. What client-side code do I need to write to pick up a custom property that my backend sends, and copy it to the DSResponse or elsewhere? Can you show an example?"

                            It then produces this code and explains the approach. The only thing wrong here is no call to Super().

                            Code:
                            isc.RestDataSource.create({
                                ID: "myRestDataSource",
                                dataFormat: "json",
                                dataURL: "/your-endpoint",
                                fields: [
                                    {name: "id", type: "integer"},
                                    {name: "name", type: "text"},
                                    // Define other fields here
                                ],
                            
                                transformResponse: function (dsResponse, dsRequest, data) {
                                    // Assuming your backend sends a custom property, e.g. 'customProperty'
                                    if (data && data.customProperty) {
                                        // Copy 'customProperty' to DSResponse or another place as needed
                                        dsResponse.customProperty = data.customProperty;
                                    }
                            
                                    // Return the modified DSResponse to proceed with default behavior
                                    return dsResponse;
                                }
                            });

                            Comment


                              #44
                              It's funny and painful you mention ChatGPT: I didn't want to bring that to the table. I've tried that actually and of course I had a different search command. One of the suggestions was using fetchData() which still doesn't fix the "auto fetch" behavior. I don't think I have the answer at the moment. It also gave me solutions with non-existing properties that didn't work. I will share the link to that chat, hope it is accessible and I have most likely asked the wrong questions.

                              It's not my goal to get these long discussions and I will probably stop asking questions, because I get this very negative energy from asking those questions and getting these kind of replies. I'm not a paying member either, so I understand your point. I was also hoping for other users to respond as well.

                              Some of my questions might have also been useful as positive criticism, but I probably failed in doing that. Sorry for that...

                              Comment


                                #45
                                And the question you've asked on ChatGPT still doesn't answer my situation that I want to access that response inside dataChanged() or dataArrived(). I need the data there and transforming the response inside the data source is not the solution to that question. As far as I know, I cannot access the response after that.

                                Comment

                                Working...
                                X