Announcement

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

    ListGrid - all checkboxes selector label

    There is a standard functionallity in smart gwt which gives you an abilility to add a column with selection checkboxes which has "select all" functionallity using checkbox placed in column header (ListGrid.setCanSelectAll(true)). Is there any chance to put any text (e.g., "Select All" label) right in the column header where "all selector" checkbox is placed?

    Please, see also attached screenshot to understand what I mean.

    Any help is appreciated!
    Attached Files

    #2
    Although it is easier to do in SmartClient (some functions haven't been exposed in SmartGWT yet), the easiest way is to a for loop through all the fields in your grid and call is isCheckboxField() on each field, when you find it ListGrid.setFieldTitle()

    Comment


      #3
      Thanks, svjard!

      1) But what is the correct place/time in java for looping through all grid columns since after I add all columns to the grid (ListGrid.setFields()) and add the grid to the panel this standard selection column is not in the list of columns when I invoke ListGrid.getFields() (only fields that were added by ListGrid.setFields() present in returned array)?

      2) And can you also point me to the correct place in SmartClient (you wrote it's the easiest way) so I could take a look and figure out if it's applicable in my project?

      PS: won't your method with ListGrid.setFieldTitle("Test Label") remove checkbox from the grid header and only "Test Label" will remain, since I need label and checkbox together?

      I appreciate your help so much!

      Comment


        #4
        1) addDrawHandler() to your list grid, this is the best time to do it. Use getAllFields() for the loop. And yes the title will be html that defines the checkbox so be careful you should be prepending your title, like myCheckboxField.setTitle("Select All<br/>" + myCheckboxField.getTitle()); and play around with how you want it to look exactly.

        2) Smartclient has getCheckboxField() to get to it faster, that is the only difference.

        Comment


          #5
          Thanks for explanations!

          I also thought I found another solution with HeaderSpan. Using this method I need to access 2 variables from ListGrid.js - to find selection column header by name "_checkboxField" (default name in ListGrid.js for checkbox field - after finding it I can put a HeaderSpan above it) and change value of "_checkboxFieldWidth" to 30 (15 is the default value) but after GWT obfuscate this names I get "$63g" and "$63n" (instead of "_checkboxField" and "_checkboxFieldWidth") in obfuscated js file. (seems that this variables are private for GWT since their names starts with "_").

          I'm not able to use "setAttribute("_checkboxFieldWidth", 30, true)" in Java but e.g. "setAttribute("$63n", 30, true)" works. So,

          1) Is there any way to force GWT compiler not to mangle (or replace with specified values) some of variables names (2 variables in this case) not using PRETTY js style (big js size, slower perfomance in this case)?

          2) Or can I use "nice" names of variables but not "$63g" in my javacode since I believe this values are dependent on some things which we cannot directly influence (gwt version and etc.)?

          3) Can I use names like "$63g" in my Java code in a pinch?

          Comment


            #6
            Using the obfuscated names is never a good idea under any condition. If you look in the SmartGwt.jar file there is a Debug directory with the correct gwt.xml files you could use to get around the minified code.

            But so is your solution to go ahead with the headerspan idea? If so again why bother with the whole $63n type stuff, what I proposed before would work just as well to set the field width for the checkbox field and always work. Instead of changing the title, just change the width, otherwise exact same code. A for loop versus setAttribute won't make a performance difference really.

            Comment


              #7
              Originally posted by svjard
              Although it is easier to do in SmartClient (some functions haven't been exposed in SmartGWT yet), the easiest way is to a for loop through all the fields in your grid and call is isCheckboxField() on each field, when you find it ListGrid.setFieldTitle()

              But I don't see any isCheckboxField() method in the ListGridField class.

              Comment


                #8
                Originally posted by asingla
                But I don't see any isCheckboxField() method in the ListGridField class.

                My bad. I got it.. It's in the ListGrid class.

                Comment


                  #9
                  Originally posted by svjard
                  addDrawHandler() to your list grid, this is the best time to do it. Use getAllFields() for the loop. And yes the title will be html that defines the checkbox so be careful you should be prepending your title, like myCheckboxField.setTitle("Select All<br/>" + myCheckboxField.getTitle());
                  I don't see the text which I added. I see the code is being called and eveything is working but I still see only checkbox.

                  Comment


                    #10
                    It should work if your using the stuff I posted. However that being said, your issue will always be that whenever the grid has to redraw for any reason, it will always revert back to the original header. Ultimately you can't permanently change it since the ListGrid always calls getValueIconHTML() and unless you have your own implementation of it then you can force the header to contain your text.

                    You could define your own class MyListGrid in your html that extends ListGrid, and overwrite getValueIconHTML, just copy and paste the original implementation and change the return line to be return name + '<br/>' + iconHTML;, setup an attribute you can easily set the 'name' too. Then just call up that class in your java code.

                    Comment


                      #11
                      Hi,

                      I have the same problem ,I don't see the text which I added. I see the code is being called and eveything is working but I still see only checkbox.

                      Can you please tell how did u fix it. if possible can you please send the code.

                      Comment


                        #12
                        I was not able to fix this. I rather implemented the "Select All" functionality by showing the first list grid record as "All" provided all the feature of select all when user was selecting/deselecting this record/

                        Comment


                          #13
                          Hello!

                          Is it any method to label the first "Select All" checkbox in the newest smartGWT (2.5) ?

                          I tried the svjard solution using getAllFields() method, but it founds only field which was set by setFields(...)

                          I tried it using simple code:

                          Code:
                          listGrid.addDrawHandler(new DrawHandler() {
                          
                          	@Override
                          	public void onDraw(DrawEvent event) {
                          		for (ListGridField field : listGrid.getAllFields()) {
                          			if (listGrid.isCheckboxField(field)) {
                          				field.setTitle("Select All<br/>" + field.getTitle());
                          
                          			}
                          
                          			System.out.println(field.getTitle());
                          		}
                          	}
                          });
                          Best regards
                          Daniel

                          Comment


                            #14
                            Originally posted by svjard
                            It should work if your using the stuff I posted. However that being said, your issue will always be that whenever the grid has to redraw for any reason, it will always revert back to the original header. Ultimately you can't permanently change it since the ListGrid always calls getValueIconHTML() and unless you have your own implementation of it then you can force the header to contain your text.

                            You could define your own class MyListGrid in your html that extends ListGrid, and overwrite getValueIconHTML, just copy and paste the original implementation and change the return line to be return name + '<br/>' + iconHTML;, setup an attribute you can easily set the 'name' too. Then just call up that class in your java code.
                            Hi, svjard! There is no more get/set-ValueIconHTML()? Have the problem with repaintin of checkbox label after it is clicked.

                            Comment

                            Working...
                            X