Announcement

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

    How to hide checkbox-field on listgrid-cell ?

    Hi,
    We have a listgrid with some editable fields, one of the editable-fields is a checkbox-field.
    I create the checkbox-field with: field.setType(ListGridFieldType.BOOLEAN);

    The field can have 3 states: true, false or empty. If the field is empty, it must be readonly. I set it to readonly with canEditCell() if the value is null.
    1. Our customer requested to not show the checkbox, if it is empty. How can I hide the checkbox in this case (in a cell)?


    The grid is filled from a rest-service. From the server I return the values "true", "" (for false) or null (for empty).
    2. That works as desired, but are the values I return the ones as it's designed?


    (we have a large smartgwt-application with smartgwt-5.0-2015-08-20 and our customer uses Internet-Explorer 11).



    Click image for larger version

Name:	listgrid-with-checkbox.png
Views:	454
Size:	8.3 KB
ID:	250551

    #2
    Have you tried CellFormatter already?
    MichalG

    Comment


      #3
      Hi @mf,

      please see this sample.
      You should be able to archive your desired Layout with a ListGridEditorCustomizer. In the ListGridEditorCustomizer use context.getEditedRecord() to decide if you want to return the normal BooleanItem (context.getDefaultProperties()) or something else - perhaps a HiddenItem or StaticTextItem.

      Best regards
      Blama

      Comment


        #4
        Hi together,
        I looked at the smartgwt grid_custom_editing_cell showcase, but this shows the checkbox (or hides it) in edit-mode. I could not manage to display the checkbox in the not-edit-mode.
        I have to use alwaysShowEditors = false on the grid .

        the CellFormatter has to return a String. How can I turn it into a checkbox?

        regards,
        Marco

        Comment


          #5
          Just return super.format(value,record,rowNum,colNum) in cases you need standard checkbox and empty html string otherwise.
          MichalG

          Comment


            #6
            Hi,
            it's not possible to return super.format(value,record,rowNum,colNum) because CellFormatter is an interface.
            Sadly I could not manage to hide the checkbox in view-mode (it works in edit-mode) with "ordinary" methods.

            But I made it work with CellFormatter returning a checkbox-html-snippet:
            "<span class="checkboxTrue" style="width: 13px; height: 13px; margin-right: 2px; margin-left: 2px; vertical-align: text-top; display: inline-block;" eventpart="valueicon"></span>"

            This is not nice, but it works.

            Regards and thanks,
            Marco

            Comment


              #7
              I see, but better use lg.getDefaultFormattedValue() instead of super like in the following example:
              Code:
              package pl.com.tech4.client;
              
              import com.google.gwt.core.client.EntryPoint;
              import com.smartgwt.client.data.DataSourceField;
              import com.smartgwt.client.data.RestDataSource;
              import com.smartgwt.client.data.fields.DataSourceDateField;
              import com.smartgwt.client.data.fields.DataSourceFloatField;
              import com.smartgwt.client.data.fields.DataSourceTextField;
              import com.smartgwt.client.types.FieldType;
              import com.smartgwt.client.widgets.grid.CellFormatter;
              import com.smartgwt.client.widgets.grid.ListGrid;
              import com.smartgwt.client.widgets.grid.ListGridRecord;
              
              public class MainEntryPoint implements EntryPoint {
              
                  public void onModuleLoad() {
              
                      layout();
                  }
              
                  private void layout() {
              
                      final RestDataSource ds = new RestDataSource();
                      ds.setDataURL("UnitDir.xml");
                      DataSourceField fieldId = new DataSourceField();
                      fieldId.setName("id");
                      fieldId.setPrimaryKey(true);
                      fieldId.setHidden(true);
                      DataSourceTextField fieldCode = new DataSourceTextField();
                      fieldCode.setName("code");
                      DataSourceField fieldQuantity = new DataSourceField();
                      fieldQuantity.setName("quantity");
                      fieldQuantity.setType(FieldType.LOCALEFLOAT);
                      DataSourceDateField fieldValidFrom = new DataSourceDateField();
                      fieldValidFrom.setName("validFrom");
                      ds.setFields(fieldId, fieldCode, fieldQuantity, fieldValidFrom);
              
                      final ListGrid lg = new ListGrid();
                      lg.setDataSource(ds);
                      lg.setAutoFetchData(true);
                      lg.setCanAddFormulaFields(true);
                      lg.setWidth(300);
                      lg.setCellFormatter(new CellFormatter() {
                          @Override
                          public String format(Object value, ListGridRecord record, int rowNum, int colNum) {
                              if (colNum == 1 && rowNum == 1) {
                                  return "*";
                              } else {
                                  return lg.getDefaultFormattedValue(record, rowNum, colNum);
                              }
                          }
                      });
              
                      lg.draw();
                  }
              }
              Click image for larger version

Name:	cellformat.png
Views:	276
Size:	7.3 KB
ID:	250581
              MichalG

              Comment


                #8
                Hi mf,

                I had a look at the docs: Try this API ListGrid.setBooleanFalseImage() and set it to an empty image. Do not use a broken URL, as one browser, I think FF, will display a "missing image"-icon then.

                Best regards
                Blama

                Comment


                  #9
                  Hi,
                  The grid is filled from a rest-service. From the server I return the values "true" (for checked), "" (for unchecked).
                  Is it possible to return a value, so that the checkbox is partially selected? Or how could I do this?

                  Regards,
                  Marco Füllemann

                  Comment


                    #10
                    See here and the same for false. I assume that if you really send empty strings, this is even more easy.
                    If using only LGPL: Don't know how this works in a Java (=non .ds.xml) DataSource, but I assume it is somehow similar. If not you need to transform the response before.
                    But this is not connected to your image-problem, is it? If this is still about the same, see #8 and exchange images for null and partial?

                    Comment

                    Working...
                    X