Announcement

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

    ListGrid select box in header

    Is there any way to change the value of the select box in the header for ListGrids which are setup like this:

    listGrid.setSelectionAppearance(SelectionAppearance.CHECKBOX);

    We have a case where all the items in the ListGrid are selected, but the header check box is not? Would like to programatically set the header checkbox to true.

    #2
    What is interesting is we explicitly do at listGrid.selectAllRecords(); and all the records are selected except the one in the Header?

    So is there a way programatically we can set the checkbox in the header as a work-around?

    Comment


      #3
      It should be automatically selected, and it is in samples. What is your version and browser, what skin are you seeing this in, and what are the settings on your grid?

      Comment


        #4
        SC_SNAPSHOT-2011-01-06/PowerEdition Deployment 2011-01-06
        GWT 1.7.1
        IE, FireFox, Chrome

        We have a custom widget that uses a ListGrid, and when we populate the widget we set all of the items to selected, but for some reason, the checkbox in the Header is set to false. I double checked to see what image is being used and it is the 'unchecked.png' image, so I assume everything is working.

        Attached you'll see an image of the custom widget.

        The ListGrid is setup as follows:
        Code:
        private ListGrid createGrid(Criteria criteria, DataSource dataSource){
                    ListGridField[] listGridFields = new ListGridField[1];
        
                    listGridFields[0] = new ListGridField("value", "Select All");
                    listGridFields[0].setCanGroupBy(Boolean.FALSE);
                    listGridFields[0].setCanHide(Boolean.FALSE);
                    listGridFields[0].setCanFreeze(Boolean.FALSE);
        
                    ListGrid listGrid = new ListGrid(){
                        @Override public ListGridRecord[] getSelection() {
                            ListGridRecord[] records = super.getSelection();
                            if(records == null) records = new ListGridRecord[0];
                            return records;
                        }
                    };
                    listGrid.setHeight100();
                    listGrid.setAlternateRecordStyles(Boolean.TRUE);
                    listGrid.setSelectionAppearance(SelectionAppearance.CHECKBOX);
                    listGrid.setAutoFetchData(Boolean.FALSE);
                    if(dataSource != null) listGrid.setDataSource(dataSource);
                    if(criteria != null) listGrid.setInitialCriteria(criteria);
                    listGrid.setFields(listGridFields);
        
                    listGrid.addDataArrivedHandler(new DataArrivedHandler() {
                        public void onDataArrived(DataArrivedEvent event) {
                            updateValueState();
                            notifyDimensionValesLoadedListeners(new ChangeEvent(""));
                        }
                    });
        
                    return listGrid;
                }
        Attached Files

        Comment


          #5
          One more code snippet:
          Code:
          private void updateValueState(){
                      listGrid.selectAllRecords();
                      
                      for (Dimension dimension : cubeMeta.getSelectedDimensions()) {
                          if(dimension.getId() == getDimension().getId()){
                              if(dimension.getFilterValues() != null && dimension.getFilterValues().length > 0) {
                                  listGrid.deselectAllRecords();
                                      for (int i = 0; i < listGrid.getTotalRows(); i++) {
                                          ListGridRecord listGridRecord = listGrid.getRecord(i);
                                          if(dimension.contains(listGridRecord.getAttribute("value"))) {
                                              listGrid.selectRecord(i);
                                              setIcon(null);
                                              setIcon(FILTERED_IMAGE);
                                          }
                                      }
                              }
                          }
                      }
                  }

          Comment


            #6
            So you can see in the ListGrid onDataArrived event, we make a call to updateValueState(), where a listGrid.selectAllRecords() is called.

            When all is said and done, the widget appears like in the screen shot I provided, all of the records are selected, but the checkbox in the header is not.

            Is there a way I can explicitly change the checkbox in the header to true?

            Comment


              #7
              Can you try running this code on a delay after DataArrived (use DeferredCommand) to see whether we have a timing issue involved?

              Comment


                #8
                Do you mean put a timer before the updateValueState() call in onDataArrived?

                Comment


                  #9
                  This is what I tried, and it had no affect:
                  Code:
                  listGrid.addDataArrivedHandler(new DataArrivedHandler() {
                                  public void onDataArrived(DataArrivedEvent event) {
                                      Timer t = new Timer() {
                  
                                          @Override
                                          public void run() {
                                              DeferredCommand.addPause();
                                              DeferredCommand.addCommand(new Command(){
                  
                                                  public void execute() {
                                                      updateValueState();
                                                      notifyDimensionValesLoadedListeners(new ChangeEvent(""));
                                                  }
                                              });
                                              
                                          }
                                      };
                                      t.schedule(3000);
                                  }
                              });

                  Comment


                    #10
                    A little unclear on what the report is here - looking at your logic, it appears to only select some records. Do you have an issue if you simply call selectAllRecords(), with no custom logic, on a DeferredCommand from DataArrived, with all records loaded?

                    Comment


                      #11
                      No problem, I commented out the logic in question as follows, and still no change in behavior:

                      Code:
                      private void updateValueState(){
                                  listGrid.selectAllRecords();
                                  
                      //            for (Dimension dimension : cubeMeta.getSelectedDimensions()) {
                      //                if(dimension.getId() == getDimension().getId()){
                      //                    if(dimension.getFilterValues() != null && dimension.getFilterValues().length > 0) {
                      //                        listGrid.deselectAllRecords();
                      //                            for (int i = 0; i < listGrid.getTotalRows(); i++) {
                      //                                ListGridRecord listGridRecord = listGrid.getRecord(i);
                      //                                if(dimension.contains(listGridRecord.getAttribute("value"))) {
                      //                                    listGrid.selectRecord(i);
                      //                                    setIcon(null);
                      //                                    setIcon(FILTERED_IMAGE);
                      //                                }
                      //                            }
                      //                    }
                      //                }
                      //            }
                                  
                      
                              }
                      
                          }

                      Comment


                        #12
                        In the screen shot that I provided, in that state, when I uncheck one of the reccords and then check it again, the top header check box get's set as true showing the check in the box. So it appears to be working fine. The only issue is, when I do a listGrid.selectAllRecords(), the header check box is not set to true and is unchecked.

                        Is there any work around to explicitly check the header check box?

                        Comment


                          #13
                          We're not reproducing this issue on our end.
                          Here's the simple standalone test we put together based on your sample code.

                          Code:
                          public class CheckboxSelectionHeaderIssue implements EntryPoint {
                          
                              private ListGrid listGrid;
                              private ListGrid createGrid(Criteria criteria, DataSource dataSource){
                                  ListGridField[] listGridFields = new ListGridField[1];
                          
                                  listGridFields[0] = new ListGridField("value", "Select All");
                                  listGridFields[0].setCanGroupBy(Boolean.FALSE);
                                  listGridFields[0].setCanHide(Boolean.FALSE);
                                  listGridFields[0].setCanFreeze(Boolean.FALSE);
                          
                                  listGrid = new ListGrid(){
                                      @Override public ListGridRecord[] getSelection() {
                                          ListGridRecord[] records = super.getSelection();
                                          if(records == null) records = new ListGridRecord[0];
                                          return records;
                                      }
                                  };
                                  listGrid.setHeight100();
                                  listGrid.setAlternateRecordStyles(Boolean.TRUE);
                                  listGrid.setSelectionAppearance(SelectionAppearance.CHECKBOX);
                                  listGrid.setAutoFetchData(Boolean.FALSE);
                                  if(dataSource != null) listGrid.setDataSource(dataSource);
                                  if(criteria != null) listGrid.setInitialCriteria(criteria);
                                  listGrid.setFields(listGridFields);
                          
                                  listGrid.addDataArrivedHandler(new DataArrivedHandler() {
                                      public void onDataArrived(DataArrivedEvent event) {
                                          listGrid.selectAllRecords();
                                      }
                                  });
                          
                                  return listGrid;
                              }
                              public void onModuleLoad() {
                                  DataSource testDS = new DataSource();
                                  testDS.setClientOnly(true);
                                  
                                  DataSourceField f1 = new DataSourceField("value", FieldType.TEXT);
                                  testDS.setFields(f1);
                                  
                                  ListGridRecord[] data = new ListGridRecord[] {
                                    new ListGridRecord() {{ setAttribute("value", "Value 1"); }},
                                    new ListGridRecord() {{ setAttribute("value", "Value 2"); }}
                                  };
                                  
                                  testDS.setTestData(data);
                                  
                                  Criteria c = new Criteria();
                                  
                                  createGrid(c, testDS);
                                  listGrid.draw();  
                                  listGrid.fetchData();
                                  
                              }  
                          }
                          We have made a recent change to the selectAllRecords() method so there's a possibility that this was broken and inadvertently fixed but this seems unlikely. Can you verify that you still see the issue with the latest build, and if so see if you could put together a standalone test case we could run on our end?

                          Note: No need to show us any custom server side logic, just the client side code and the raw response that's actually sent to the client for the fetch operation would be enough for us to run a standalone test case on our end.
                          You should be able to copy/paste that response out of the RPC tab of the developer console.

                          Comment


                            #14
                            Ok, I will circle back to this issue when we upgrade again and spend more time with it, thanks.

                            Comment


                              #15
                              Originally posted by Isomorphic
                              We're not reproducing this issue on our end.
                              Here's the simple standalone test we put together based on your sample code.

                              Code:
                              public class CheckboxSelectionHeaderIssue implements EntryPoint {
                              
                                  private ListGrid listGrid;
                                  private ListGrid createGrid(Criteria criteria, DataSource dataSource){
                                      ListGridField[] listGridFields = new ListGridField[1];
                              
                                      listGridFields[0] = new ListGridField("value", "Select All");
                                      listGridFields[0].setCanGroupBy(Boolean.FALSE);
                                      listGridFields[0].setCanHide(Boolean.FALSE);
                                      listGridFields[0].setCanFreeze(Boolean.FALSE);
                              
                                      listGrid = new ListGrid(){
                                          @Override public ListGridRecord[] getSelection() {
                                              ListGridRecord[] records = super.getSelection();
                                              if(records == null) records = new ListGridRecord[0];
                                              return records;
                                          }
                                      };
                                      listGrid.setHeight100();
                                      listGrid.setAlternateRecordStyles(Boolean.TRUE);
                                      listGrid.setSelectionAppearance(SelectionAppearance.CHECKBOX);
                                      listGrid.setAutoFetchData(Boolean.FALSE);
                                      if(dataSource != null) listGrid.setDataSource(dataSource);
                                      if(criteria != null) listGrid.setInitialCriteria(criteria);
                                      listGrid.setFields(listGridFields);
                              
                                      listGrid.addDataArrivedHandler(new DataArrivedHandler() {
                                          public void onDataArrived(DataArrivedEvent event) {
                                              listGrid.selectAllRecords();
                                          }
                                      });
                              
                                      return listGrid;
                                  }
                                  public void onModuleLoad() {
                                      DataSource testDS = new DataSource();
                                      testDS.setClientOnly(true);
                                      
                                      DataSourceField f1 = new DataSourceField("value", FieldType.TEXT);
                                      testDS.setFields(f1);
                                      
                                      ListGridRecord[] data = new ListGridRecord[] {
                                        new ListGridRecord() {{ setAttribute("value", "Value 1"); }},
                                        new ListGridRecord() {{ setAttribute("value", "Value 2"); }}
                                      };
                                      
                                      testDS.setTestData(data);
                                      
                                      Criteria c = new Criteria();
                                      
                                      createGrid(c, testDS);
                                      listGrid.draw();  
                                      listGrid.fetchData();
                                      
                                  }  
                              }
                              We have made a recent change to the selectAllRecords() method so there's a possibility that this was broken and inadvertently fixed but this seems unlikely. Can you verify that you still see the issue with the latest build, and if so see if you could put together a standalone test case we could run on our end?

                              Note: No need to show us any custom server side logic, just the client side code and the raw response that's actually sent to the client for the fetch operation would be enough for us to run a standalone test case on our end.
                              You should be able to copy/paste that response out of the RPC tab of the developer console.
                              Dear Isomorphic and Jasmith, your posts is really helpful with me! Thanks so much!

                              It is good with 2 cases:
                              - Select all and select some item.

                              - Select all:

                              listGrid.setData(serviceRecords);
                              listGrid.selectAllRecords();

                              - Select some items: listGrid.selectRecord(record);

                              Comment

                              Working...
                              X