Announcement

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

    SmartGWT ListGrid InvalidateCache is not discarding unsaved edits

    I have a question with regards to SmartGWT ListGrid.

    The following use case explains,

    There is one ComboBoxItem which has few records loaded in them. There is ListGrid just beneath the ComboBoxItem.

    ComboItem has ChangeEvent (not Changed) Handler which captures user changes. Also this change triggers fetchData on ListGrid which will populate the same.

    Now after user does some edits on ListGrid and without saving them (setAutoSaveEdits is false), user goes ahead and changes the selection in ComboBoxItem which actually calls a fetch operation on ListGrid then ideally i should receive a confirm to discard edits. (with OK ,SAVE CANCEL buttons).

    However before the ListGrid.fetchData i make a call ListGrid.InvalidateCache . This call to invalidate cache is making the ListGrid not capture the unsaved edits(as in not showing the confirm discard edit popup) to the ListGrid which makes me think that the unsaved edits are discarded BUT it is not discarding the edits. The next time i select the same record it is showing up the record with the edit value still existing.

    Shouldn't InvalidateCache on ListGrid discard the unsaved edits as well ?

    Following is my sample code..

    Code:
        ComboBoxItem fileSelectItem = new ComboBoxItem("Select Item",
                "Select a Record");
        fileSelectItem.setAddUnknownValues(Boolean.FALSE);
        fileSelectItem.setValueField("id");
        fileSelectItem.setDisplayField("description");
        fileSelectItem.setRequired(true);
        fileSelectItem.setWidth(600);
    
        final ListGrid grid = new ListGrid();
    
        fileSelectItem
                .addChangeHandler(new com.smartgwt.client.widgets.form.fields.events.ChangeHandler() {
    
                    @Override
                    public void onChange(ChangeEvent event) {
                        grid.invalidateCache();
                        grid.fetchData(new Criteria("key", "value"));
                    }
                });

    #2
    Hi chebus,

    please see this javadoc. You shouldn't use invalidateCache() and fetchData(...) together. I also think that your fetch(...) should be enough.
    Did you already see setConfirmDiscardEdits(java.lang.Boolean)?

    For more information Isomorphic will have to jump in.

    Best regards,
    Blama

    Comment


      #3
      To discard all edits, call discardAllEdits().

      Comment


        #4
        Thanks for the reply.

        setConfirmDiscardEdits by default is true. I set it to false , And i am creating my own confirm dialog to have my own logic for Ok,save and cancel clicks.

        I guess what I need to do is when the user changes the criteria, I need to check if there are any edits on the grid (grid.hasChanges) and then show up my popup.This is working fine.

        However ,if i cannot use InvalidateCache along with fetchData().
        How can i force the server call with new Criteria ?
        ?

        I am asking this because fetchData(criteria) is not working (as in it will not refresh the grid with new set of records for the new criteria) when "there are any pending unsaved edits in the ListGrid" .

        Thanks.

        Comment


          #5
          Did you see Isomorphic's answer?

          Comment


            #6
            Blama - Yes i have seen it. I knew i can use discardAllEdits to discard all of pending unsaved edits. But i have a requirement when user navigates away from the unsaved edits i need to show up a popup (Ok ,Cancel with my logic) .

            Specifically On click of ok ,i need to re-load the ListGrid with the new criteria. This is not working when use only fetchData() all alone.

            I found something which makes this possible .However i am not sure if it is neat.

            ListGrid.setData(new Record[1])
            ListGrid.fetchData(new Criteria("key","value")

            Thanks

            Comment


              #7
              I don't get it.

              Originally posted by chebus View Post
              I guess what I need to do is when the user changes the criteria, I need to check if there are any edits on the grid (grid.hasChanges) and then show up my popup.This is working fine.
              So you have your popup.
              In case of "OK" do a saveAllEdits() and then, perhaps in the callback, the new fetchData(...).
              In case of "Cancel edits" do a discardAllEdits() and then the new fetchData(...).

              Doesn't that work?

              Comment


                #8
                Ok click - discard edits, fetch data with new criteria on ListGrid
                Cancel click - hide the popup and stay where we are !

                To acheive Ok click, first i tried with the following,

                discardEdits()
                fetchData(new Criteria("k","v")) // this is vague sometimes works ,sometime won't

                then i tried with the following snippet which worked fine..

                discardEdits()

                if(ListGrid.willFetchData())
                fetchData(new Criteria(k,v))
                else
                setData(new Record[1]) // had forcibly make the Grid empty.
                fetchData(new Criteria(k,v))

                Thanks!

                Comment


                  #9
                  I have a confusion.
                  AS javadoc says that "If necessary, invalidateCache will cause a new fetch to be performed with the current set of criteria for this component"

                  Is there any way to know that it call a fetch whenever i call invalidateCache(). ??

                  Actually sometimes invalidateCache() call fetch and sometimes not.

                  Is it necessary to use invalidateCache() ??
                  If i don't call invalidateCache() and only call fetchData() then any problem can occur ?? if yes then which type of problem can occur ??

                  Please help me and clear my confusion.?

                  Comment

                  Working...
                  X