Announcement

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

    listGrid header checkbox issue with selectAllRecords() call.

    Hi

    I have list grid constructed like below. The problem we are facing is when we call listgrid.selectAllRecords() method - it selects all the records but does not check header checkbox.

    It works fine with user interaction. I mean when user click on header checkbox - it select all records/deselect all records.

    Code:
                ListGridField[] listGridFields = new ListGridField[1];
                listGridFields[0] = new ListGridField("value");
                listGridFields[0].setCanGroupBy(Boolean.FALSE);
                listGridFields[0].setCanHide(Boolean.FALSE);
                listGridFields[0].setCanFreeze(Boolean.FALSE);
    
                listGrid = new ListGrid();
                listGrid.setHeight100();
                listGrid.setAlternateRecordStyles(Boolean.TRUE);
                listGrid.setSelectionAppearance(SelectionAppearance.CHECKBOX);
                listGrid.setAutoFetchData(Boolean.FALSE);
                listGrid.setFields(listGridFields);
    Any suggestion?

    #2
    Are you doing any type of refresh? The function to check/uncheck that is internal, no wrapper, so you need to refresh so the grid sees everything is selected I believe.

    Comment


      #3
      No luck .. i even try to redraw the widget.

      I hope grid is not taking up paging into consideration - b'cause the the only reason i can think of for not checking the header checkbox on selectAllRecords call.

      Little bit more info: I didn;t set any datasource on that grid, instread i am fetching the data myself and setting into grid via listGrid.setData(response.getData()); call.

      I would appreciate any kinda clue..

      Comment


        #4
        I think you need to file an enhancement request for this issue. I looked at the code and you would need to call ListGrid.headerClick(fieldNum, header) which is a Javascript function, so no wrapper in SmartGWT, you would instead need to use JSNI to call it and force update the checkbox in the header.

        The way it works internally is:
        On clicking the header it calls, headerClick() --> _setCheckboxHeaderState() which then sets the icon.

        Comment


          #5
          Thanks for the quick reply. I really appreciate that.

          But i don't think it could be a missing feature in SmartGWt. I know th API and company behind it.. people would have gone nuts for a so common feature like that.. I am quite +ve that i might be missing something .. and i just need a signal in right direction..

          SmartGWt people are pretty quick in terms of replying thread.. let's see when someone get the time to breath .. :)

          Comment


            #6
            I have the same problem. When I refresh my listgrid I get the selected state, and then after I fetch data, I set the selected state. However, if user selects all records, then header checkbox is not selected.

            Is there a solution for this?

            Comment


              #7
              Originally posted by rathiandi
              Thanks for the quick reply. I really appreciate that.
              Hi rathiandi,

              It looks like you got how to do it. Can you please share the code? I didn't get what is header in the javascript function and how to call this method in JSNI way. your help will be much appriciated.

              Comment


                #8
                selectAllRecords() should select the header checkbox, try it, if it doesn't post your version information.

                Comment


                  #9
                  No it is not doing so. It is checking all the records but not the header chexkbox. I am using the latest smartgwt-2.2.zip from the google code base with gwt-2.0.3. Let me know if you want any more information.

                  Thanks for replyig.

                  Comment


                    #10
                    Our of curiosity how are your populating your grid and when are you calling selectAllRecords(). Here is a workaround to try as well.
                    Code:
                    public class MyListGrid extends ListGrid {
                      private native void _setCheckboxHeaderState(boolean state) /*-{
                        var self = this.@com.smartgwt.client.widgets.BaseWidget::getOrCreateJsObj()();
                        self._setCheckboxHeaderState(state);
                      }-*/;
                    };
                    You can call _setCheckboxHeaderState(true) whenever you call selectAllRecords() to set the checkbox field manually for now.

                    Comment


                      #11
                      I will try this. BTW this my code which is not selecting the checkbox in the header.
                      Code:
                      public class MultiSelectCriteiraGrid extends ListGrid
                      {
                          public static String FIELD_ID = "id";
                      
                          public static String FIELD_PID = "pid";
                      
                          public static String FIELD_VALUE = "value";
                      
                          public MultiSelectCriteiraGrid(final String title)
                          {
                              setWidth(220);
                              setShowAllRecords(true);
                              setAlternateRecordStyles(true);
                              setLeaveScrollbarGap(false);
                              setSelectionType(SelectionStyle.SIMPLE);
                              setSelectionAppearance(SelectionAppearance.CHECKBOX);
                              setCanSelectAll(false);
                              final ListGridField fieldId = new ListGridField(FIELD_ID);
                              fieldId.setHidden(true);
                              final ListGridField parentId = new ListGridField(FIELD_PID);
                              parentId.setHidden(true);
                              final ListGridField fieldName = new ListGridField(FIELD_VALUE, title);
                              fieldName.setCanSort(false);
                              fieldName.setCanGroupBy(false);
                              fieldName.setCanHide(false);
                              fieldName.setCanDragResize(false);
                              setFields(fieldId, parentId, fieldName);
                          }
                      
                          public void setData(final Collection<ReportDimensionValue> values)
                          {
                              final Collection<ListGridRecord> records = new ArrayList<ListGridRecord>();
                              for(final ReportDimensionValue value : values)
                              {
                                  records.add(getRecord(String.valueOf(value.getId()), String.valueOf(value.getParentId()), value
                                          .getValue()));
                              }
                              super.setData(records.toArray(new ListGridRecord[records.size()]));
                              selectAllRecords();
                          }
                          private ListGridRecord getRecord(final String id, final String pid, final String value)
                          {
                              ListGridRecord record = new ListGridRecord();
                              record.setAttribute(FIELD_ID, id);
                              record.setAttribute(FIELD_PID, id);
                              record.setAttribute(FIELD_VALUE, value);
                              return record;
                          }
                      }

                      Comment


                        #12
                        Yea I think it is just a fix that Isomorphic needs, but the workaround works fine for me. Interestingly in the right scenario will work, but most cases doesn't.

                        Comment


                          #13
                          Originally posted by svjard
                          You can call _setCheckboxHeaderState(true) whenever you call selectAllRecords() to set the checkbox field manually for now.
                          I am sorry but this also didn't work. It looks like some javascript error as my page didn't appear. I am sorry but I am very naive in debugging javascript. I do have firebug but I didn't see any javascript error there with regards to this.
                          I just make a call to _setCheckboxHeaderState(true); right after selectAllRecords(); (code posted in last post)

                          Comment


                            #14
                            Actually make sure it is public not private method. It should be just another function in your MultiSelectCriteiraGrid class. Then call it as you would selectAllRecords() or any other function. Post your code if you still get an error.

                            Comment


                              #15
                              Code:
                              public native void _setCheckboxHeaderState(boolean state) /*-{
                                  var self = this.@com.smartgwt.client.widgets.BaseWidget::getOrCreateJsObj()();
                                  self._setCheckboxHeaderState(state);
                                    }-*/;
                              this is what i put in the my class and called this method right after the selectAllRecords() method. I put an alert on self object and was able to see that object is being found. But i am not able to understand the call to _setCheckboxHeaderState(state); method which looks like a recusrsive call to this method itself. I checked the ISC_Grids.js and saw this method function isc_ListGrid__setCheckboxHeaderState.

                              are you sure the call self._setCheckboxHeaderState(state); is valid call?
                              Please don't mind if this is a silly question as I am making sure there is no typing mistake here.

                              Comment

                              Working...
                              X