Announcement

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

    smartgwt listgrid search on cached data remove selected records

    Hi Team,

    I have a multiple selected list grid bounded by datasource and have search on each field.User select few record in the list grid and then search on grid and clear search filter afterword.
    Now my grid have all record unselected. Is there any way local cache of this listgrid can maintain the selected records.

    Thanks,
    Parvesh Goyal

    #2
    Hi,
    before on entering search box, call getSelectedRecords() and store this, and afterwards, call selectRecords().

    Should work, shouldn’t it?

    Best regards
    Blama

    Comment


      #3
      It's not a good idea to try to maintain a selection of records that have been hidden by filtering. It means that if the end user takes some kind of action like deleting or moving all selected records, they are acting on records they can't see.

      Comment


        #4
        Hi Team,

        The issue is with the listgrid local cache. List grid local cache does not have the selected item records in its cache so it remove it once filter cleared(As data then get rendered from local cache) .Is there any event which we can fire when data get rendered from local cache or is there any way we can update local cache.

        Thanks,
        Parvesh Goyal

        Comment


          #5
          Yes, as indicated above, that’s intentional. If you want to override this behavior, you could capture the selected records before filters are applied, or you could use an actual field of type:”Boolean” to store information if you intend it to be permanent.

          The set of selected records does not persist after filtering, by design.

          Comment


            #6
            Hi Team,

            I have captured the user selected records in the list before applying filter.Now user apply a filter and later on clear that filter to get the complete data again in listGrid. In this case it render the list from the local cache. There is no way to capture event when list grid serve data from local cache. I need to update data for selected records when it get rendered from local cache.
            Last edited by preeti_kanyal; 30 Nov 2019, 02:25.

            Comment


              #7
              To reiterate, having selected items that are hidden from the user is generally a bad UE.

              If you want to implement a bad UE, you are presumably calling some API to clear the filter criteria, so that's when you would re-select the records that you are trying to maintain as the selection.

              If you are referring to the end user clearing filter criteria by eg editing filter criteria in the filter editor, DataChanged fires as does filterEditorSubmit - remember, SmartGWT comes with documentation, so these things are easy to determine.

              Comment


                #8
                I had the same issue when filtering. I solved it by using a Map to store the selected records with the record's primary key as the map key.
                Then, using addDataChangedHandler, I stream through the results and select the related records.
                This method solves the issue of only selecting records that are listed in the grid as well.


                Code:
                grid.addDataChangedHandler(event ->
                grid.selectRecords(Arrays.stream(grid.getRecords()).filter(listGridRecord -> MAP.containsKey(listGridRecord.getAttributeAsLong(PRIMARY_KEY))).toArray(Record[]::new)));
                Hope this helps.

                Comment

                Working...
                X