Announcement

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

    Removing all Records from a ListGrid (Client Only)

    Hi,

    i'am using a ListGrid with client use only. Adding of Records works well but i don't get "removing of all records" implemented.

    Here the definition of the ListGrid and DataSource
    Code:
    //ListGrid stuff
    ListGrid listGridLayout = new ListGrid();
    ListGridField fieldName = new ListGridField("name", "Name");
    ListGridField fieldUrl = new ListGridField("url", "Url");
    ListGridField fieldMultiContent = new ListGridField("multicontent", "Multi content");
    ListGridField fieldMultiTitle = new ListGridField("multititle", "Multi title");
    
    DataSource listGridLayoutDataSource = new DataSource();
    DataSourceTextField nameDataSource = new DataSourceTextField("name");
    DataSourceTextField urlDataSource = new DataSourceTextField("url");
    DataSourceTextField multiContentDataSource = new DataSourceTextField("multicontent");
    DataSourceTextField multiTitleDataSource = new DataSourceTextField("multititle");
    
    listGridLayout.setShowAllRecords(true);
    listGridLayout.setAutoFetchData(true);
    listGridLayout.setFields(fieldName, fieldUrl, fieldMultiContent, fieldMultiTitle);
    
    listGridLayoutDataSource.setClientOnly(true);
    listGridLayoutDataSource.setID("LayoutGrid");
    listGridLayoutDataSource.setFields(nameDataSource, urlDataSource, multiContentDataSource, multiTitleDataSource);
    listGridLayout.setDataSource(listGridLayoutDataSource);
    That is the method which adds records to ListGrid, this works well and with out problems...
    Code:
        public void addRecordsToTreeGrid(ListGridRecord records[]) {
            for (int i = 0; i < records.length; i++) {
                listGridLayoutDataSource.addData(records[i]);
            }
        }
    And that is the method which should remove all records from the ListGrid, that works completly not ;) and is my problem
    Code:
        public void clearRecordList() {
            ListGridRecord[] tst = listGridLayout.getRecords();
            for(int i = 0; i < tst.length; i++) {
                listGridLayoutDataSource.removeData(tst[i]);
                listGridLayout.refreshRow(i);
            }
        }
    Knows some one what is wrong? Or what i have to do diffrent to get it to work?
    Thanks for help :)

    #2
    I believe its because the grid is designed to be data-bound and data would ever rarely change so much that all data must be removed.

    However this is something that does work:

    grid.selectAllRecords();
    grid.removeSelectedData();

    It will be a little slower , since all records will need to be highlighted (you may be able to tweak this with disabling highlighting / css )

    Comment


      #3
      Originally posted by AndreiK
      I believe its because the grid is designed to be data-bound and data would ever rarely change so much that all data must be removed.

      However this is something that does work:

      grid.selectAllRecords();
      grid.removeSelectedData();

      It will be a little slower , since all records will need to be highlighted (you may be able to tweak this with disabling highlighting / css )
      At first thanks for repling. I tried it but it doesn't work

      when i call
      Code:
              listGridLayout.selectAllRecords();
              listGridLayout.removeSelectedData();
      the rows will be selected but they are not removed... that's strange ^^

      Comment


        #4
        Maybe try a

        grid.redraw(); right after?

        I have this in my code and it works and I do have clientOnly as well

        Comment


          #5
          Originally posted by AndreiK
          Maybe try a

          grid.redraw(); right after?

          I have this in my code and it works and I do have clientOnly as well
          no, does not work as well :/

          Comment


            #6
            I also disable the grid prior to this so try

            disable
            selectall
            removeselected
            enable
            redraw

            Comment


              #7
              Originally posted by AndreiK
              I also disable the grid prior to this so try

              disable
              selectall
              removeselected
              enable
              redraw
              I tried it with
              Code:
                      listGridLayout.disable();
                      listGridLayout.selectAllRecords();
                      listGridLayout.removeSelectedData();
                      listGridLayout.enable();
                      listGridLayout.redraw();
              but does not work to. Are maybe some of the attributes of the DataSource wrong?

              Comment


                #8
                Try adding listGridLayout.removeSelectedData(); to a DeferredCommand, or get the RecordList from the ListGrid and call API's on it.

                Comment


                  #9
                  Originally posted by smartgwt.dev
                  Try adding listGridLayout.removeSelectedData(); to a DeferredCommand, or get the RecordList from the ListGrid and call API's on it.

                  what do you mean with "DeferredCommand"?

                  Comment


                    #10
                    Look for it in the GWT javadocs.

                    Comment


                      #11
                      Originally posted by smartgwt.dev
                      Try adding listGridLayout.removeSelectedData(); to a DeferredCommand, or get the RecordList from the ListGrid and call API's on it.
                      Hi,

                      i tried it now on this way:

                      Code:
                              try {
                                  listGridLayout.disable();
                                  listGridLayout.selectAllRecords();
                                  
                                  Command cmd = new Command() {
                      
                                      public void execute() {
                                          listGridLayout.removeSelectedData();
                                          listGridLayout.enable();
                                          listGridLayout.redraw();
                                      }
                                  };
                                  
                                  DeferredCommand.addCommand(cmd);
                      
                                  //listGridLayout.fetchData();
                                  //listGridLayoutDataSource.fetchData();
                              }
                              catch(Exception e) {
                                  Window.alert(e.getMessage());
                              }
                      ... and it does not work...

                      ...the second idea from you i tried at first (look at my first post) but does not work to

                      Comment


                        #12
                        Now i tried it this way:

                        Code:
                            public void clearRecordList() {
                                try {
                                    Command cmd = new Command() {
                                        public void execute() {
                                            ListGridRecord[] tst = listGridLayout.getRecords();
                                            for(int i = 0; i < tst.length; i++) {
                                                listGridLayoutDataSource.removeData(tst[i]);
                                                listGridLayout.removeData(tst[i]);
                                                listGridLayout.fetchData();
                                            }
                                        }
                                    };
                                    DeferredCommand.addCommand(cmd);
                                }
                                catch(Exception e) {
                                    Window.alert(e.getMessage());
                                }
                            }
                        but does not work... it looks more and more like a realy horrible bug in smartGWT :/

                        Comment


                          #13
                          I found a "work a round" for the problem!!!!!

                          And here is the "solution"!!!:

                          Code:
                                  try {
                                      DeferredCommand.addCommand(new Command() {
                          
                                          public void execute() {
                                              listGridLayoutDataSource.destroy();
                                          }
                                      });
                          
                                      DeferredCommand.addCommand(new Command() {
                          
                                          public void execute() {
                                              listGridLayoutDataSource = new DataSource();
                                              listGridLayoutDataSource.setClientOnly(true);
                                              listGridLayoutDataSource.setID("LayoutGrid");
                                              listGridLayoutDataSource.setFields(nameDataSource, urlDataSource, multiContentDataSource, multiTitleDataSource);
                                              listGridLayout.setDataSource(listGridLayoutDataSource);
                                          }
                                      });
                                  } catch (Exception e) {
                                      Window.alert(e.getMessage());
                                  }
                          But anyway, it is in my opinion a smartGWT bug... and it sould be fixed... is somewhere a bugtrack for smartGWT? Than i could post it as ticket :)

                          Comment


                            #14
                            You're the only one experiencing this "bug" while others are reporting that it works.

                            Don't file a ticket. Try producing a standalone test case instead.

                            Comment


                              #15
                              Originally posted by Isomorphic
                              You're the only one experiencing this "bug" while others are reporting that it works.

                              Don't file a ticket. Try producing a standalone test case instead.

                              Little coment: to get the "work around" to work:
                              Code:
                              listGridLayout.setAutoFetchData(true);
                              need to be false:
                              Code:
                              listGridLayout.setAutoFetchData(false);
                              If that is false you have to call
                              Code:
                                      listGridLayout.fetchData();
                                      listGridLayoutDataSource.fetchData();
                              for adding rows.

                              I googled the problem and i found a lot post with the same problem and no one could fix it or get it to work. Every one with the same problem used a other work around for it. So in my opinion it is a bug.
                              The most people worked around with not using of DataSource to provide the grid with datas...

                              Comment

                              Working...
                              X