Announcement

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

    Keep selected row at top on refresh

    Hello,

    I use listGrid which need to be refreshed every minutes, as we have data updated every seconds.
    I have sorted data on dateTime , so latest data are always on top.

    Now AutoRefresh invoke fetchData every minute and sometime selected row get disappear. The display limitation is only 75 rows, and then it loads on scroll down.

    How can I keep selected rows on top , regardless of sort field?

    Thanking you

    #2
    Provide a sortNormalizer that sorts rows in the way you want.

    Comment


      #3
      Isomorphic
      Pleasae provice example where, sortNormalizer can return selected rows.

      Please find below, I tried below code, does not seem to be working.

      sortNormalizer: function (record, field, context) {
      return context.getSelected();
      }

      anything wrong here ?
      Do I need to return rownumber ??\\

      Thank you.

      Comment


        #4
        Start by reading the docs for sortNormalizers. Your attempt above looks like you just made up an API rather than actually looking at the docs.

        Comment


          #5
          Hi ppratik,

          I'm not sure if this is possible easily at all. See this sample and replace the button with this code:
          Code:
          isc.Button.create({
              ID: "buttonDownload",
              width:200,
              title: "Refetch",
              click: function () { 
                      listGridSuppyItem.fetchData(initialCriteria);
              } 
          });
          For me, no fetch is issued (expected IMHO). If you did invalidateCache() instead (you said you would do fetchData() in your timer(?)), the selection is not preserved, even though I selected the top rows.
          I don't think it is possible to preserve the selection here out o the box? Is it?
          My gut feeling says: SelectionStateChanged-handler, saving the selection on change and re-apply it on dataArrived. If rows are missing, requery only those from the DS by primaryKey, (hoping that the ListGrid will include them in its data set).

          Best regards
          Blama

          Comment


            #6
            I am doing it slightly different way,
            I invalidateCache() in timer and at the same time also find and store getSelectedRecords()
            Instead of dataArrived(), I set selection row back in ds.transformResponse function.

            so, row selection are always there, but sometime at 6th page or 2nd page as more than 300 data are received in update.

            Thanking you.
            Poonam.

            I use Version v10.0p_2015-01-14/PowerEdition Development Only (2015-01-14)

            Comment


              #7
              Isomorphic
              i cant find proper documentation for sortnormalizer

              Please see link below.

              https://www.smartclient.com/smartcli...sortNormalizer

              Thanking you.

              Comment


                #8
                Hi,

                ah, yes. Saving before refresh is most likely more easy.
                Then just see the JS version of SortNormalizer. The docs you have are the correct ones.
                You have your ListGrid record in the SM. Apply the SM to one column and always sort on that column (can be hidden, too).
                In your code access your stored list of selected rows and if the row is selected return 0, else 1.

                Best regards
                Blama

                Comment


                  #9
                  Addition:
                  If not all records are on the 1st page (e.g. 75 rows), I can think of three solutions:
                  • Act on dataArrived, if not all records are included, directly fetch them from the DS via primaryKey (suggestion from #5, don't know if it will work)
                  • Use a bigger page size that will include all records that are typically selected (will fail if there are either many new records and that arbitrary new number is still too small).
                  • Somehow(?) include the selected records in the invalidateCache-request, use a custom select to create a SQL UNION of your selected records and the normal ones. That way, you won't even need a SortNormalizer - just add a column with customSelectExpression="1" and return "0" for that column in the UNION.
                  I like the last option best as it won't need fancy client code as soon as you manage to transfer the list of selected records with the request. I don't know if it is really the best.

                  Best regards
                  Blama

                  Comment


                    #10
                    Blama
                    Trouble again, I save selected rows and , trying to select them back in dataArrived handler.
                    But dataArrived is invoked only if new data arrive,

                    In that case i loose my selection,
                    Is there any alternate function ?

                    Poonam.

                    oh, realize.
                    Its not calling dataArrive handler because ListGrid is in tab and that tab is not active. UI invoke dataArrive only for active tab. List grid get refreshed but data not arrived.
                    Last edited by ppratik; 29 Aug 2017, 07:01.

                    Comment


                      #11
                      Hi,

                      invalidateCache() will always trigger dataArrived, won't it?

                      Best regards
                      Blama

                      Comment


                        #12
                        @Blama
                        It does. But only if tab is active.
                        For instance, you have 5 tabs each have Auto Refresh ListGrid .
                        Here, at a time in tabset only one tab will be selected. Now refresh will call 5 invalidateCache(), for each grid, but dataArrive() will be invoked for only one active/selected tab's listGrid.
                        When you select/activate tab then only dataArrive() function invoke.

                        This is how my smartClient 10.0 works.

                        Comment


                          #13
                          Hi,

                          I can't imagine it will depend on the tab being active if dataArrivedHandler is called.
                          Are you sure your ListGrids exists (no lazy-load on select, no destroy/recreate on select)?

                          Perhaps try this in a small testcase.

                          Best regards
                          Blama

                          Comment

                          Working...
                          X