Announcement

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

    12.0 ListGrid filterRow width problem with fixed offset

    Hi Isomorphic,

    I've been trying had to reproduce an error that has been in our app for a long time.
    I'm still not successful, but perhaps you have an suggestion. It's a complicated ListGrid, but my gut feeling says it's somehow just related to the rowNum field.
    The issue is that if you show a filterRow and then resize a column, the filterRow field positions are all wrong by a fixed offset, because the "filterfield" (disabled by default of course) over the rowNum field is too wide.
    Do you have an idea what might be causing this? I've thrown in all features here, but it does not happen in the showcase (v12.0p_2020-04-10, we use v12.0p_2020-03-11).

    I'll include a video from my app and the testcase I made so far (based on this sample, issue does not occur there, way too complicated in the end I assume, but left like this for future reference).

    Click image for larger version  Name:	filterRow field width.gif Views:	0 Size:	74.5 KB ID:	261866


    Code:
    isc.ListGrid.create({
        ID: "countryList",
        width:800,
        height:500,
        alternateRecordStyles:false,
        showRowNumbers: true,
        canRemoveRecords: true, removeFieldProperties: {width:24, canDragResize: true},
        virtualScrolling: false,
        showRecordComponents: true,
        showRecordComponentsByCell: true,
        recordComponentPoolingMode: "recycle",
        showGridSummary:true,
        showGroupSummary:true,
    
        groupByField:"continent",
        dataSource: worldDS,
        fields:[
            {name:"countryCode", width:60},
            {name:"buttonField", title: "Info", align: "center", width: 110, minWidth: 110, maxWidth: 110, canDragResize: false, canFilter:false},
            {name:"iconField", title: "Comments/Stats", width: 110, minWidth: 110, maxWidth: 110, canDragResize: false, canFilter:false},
            {name:"countryName"},
            {name:"capital"},
            {name:"continent"},
            {name:"myDate", type: "date"},
            {name:"area", formatCellValue: "isc.NumberUtil.format(value, ',0') + ' km²'"},
            {name:"population", formatCellValue: "isc.NumberUtil.format(value, ',0') + ' inhab.'"}
        ],
        autoFetchData: true,
        allowFilterExpressions: true,
        headerSpans: [
            {
                fields: ["area", "population"],
                title: "Numbers"
            },
            {
                fields: ["countryName", "continent"],
                title: "Names"
            }
        ],
        createRecordComponent : function (record, colNum) {  
            var fieldName = this.getFieldName(colNum);  
    
            if (fieldName == "iconField") {  
                var recordCanvas = isc.HLayout.create({
                    height: 22,
                    width: "100%",
                    align: "center"
                });
    
                var editImg = isc.ImgButton.create({
                    showDown: false,
                    showRollOver: false,
                    layoutAlign: "center",
                    src: "icons/16/comment_edit.png",
                    prompt: "Edit Comments",
                    height: 16,
                    width: 16,
                    grid: this,
                    click : function () {
                        isc.say("Edit Comment Icon Clicked for country : " + record["countryName"]);  
                    }
                });
    
                var chartImg = isc.ImgButton.create({
                    showDown: false,
                    showRollOver: false,
                    layoutAlign: "center",
                    src: "icons/16/chart_bar.png",
                    prompt: "View Chart",
                    height: 16,
                    width: 16,
                    grid: this,
                    click : function () {
                        isc.say("Chart Icon Clicked for country : " + record["countryName"]);  
                    }
                });
    
                recordCanvas.addMember(editImg);  
                recordCanvas.addMember(chartImg);  
                return recordCanvas;  
            } else if (fieldName == "buttonField") {  
                var button = isc.IButton.create({
                    height: 26,
                    width: 65,
                    layoutAlign: "center",
                    icon: "flags/16/" + record["countryCode"] + ".png",
                    title: "Info",
                    click : function () {
                        isc.say(record["countryName"] + " info button clicked.");
                    }
                });
                return button;  
            } else {  
                return null;  
            }  
        },
    
        updateRecordComponent: function (record, colNum, component, recordChanged) {
            var fieldName = this.getFieldName(colNum);  
            if (fieldName == "iconField") {
                var membersArray = component.getMembers();
                for (i=0;i<membersArray.size;i++) {
                    if (i == 0) {
                        membersArray[i].addProperties({
                            click : function () {
                                isc.say("Edit Comment Icon Clicked for country : " + record["countryName"]);
                            }
                        });        
                    } else {
                        membersArray[i].addProperties({
                            click : function () {
                                isc.say("Chart Icon Clicked for country : " + record["countryName"]);
                            }
                        });
                    }
                }    
            } else if (fieldName == "buttonField") {      
                component.addProperties({
                    icon: "flags/16/" + record["countryCode"] + ".png",
                    click : function () {
                        isc.say(record["countryName"] + " info button clicked.");
                    }
                });
            } else {  
                return null;  
            }  
            return component;
        }
    
    })
    
    isc.IButton.create({
        ID:"filterButton",
        title:"Filter",
        click : function () {
            countryList.setShowFilterEditor(!countryList.showFilterEditor);
        }
    })
    
    isc.HLayout.create({
        width: "100%",
        height: "100%",
        members: [ countryList, isc.LayoutSpacer.create({ width: 20 }), filterButton]
    });

    Thank you & Best regards
    Blama

    #2
    Presumably you think this is related to the rowNum field because, if you don't use that feature, the problem goes away in your app?

    If so, you could create a field that behaves similarly to the rowNum field, perhaps by copying its default properties (listed in ListGrid.js, look for listGrid.rowNumberField, or you could dynamically inspect to find them) until you get the same problem.

    Comment


      #3
      Hi Isomorphic,

      thanks. I tried now coming from my application, finally getting me to a testcase.
      Removing the showRowNumbers-field removes the problem. I then tried what else is needed for the problem to occur and started with removing my whole ListGrid.setDefaultProperties(), which includes a setMinFieldWidth(50). This alone fixes it as well.
      Then things got strange to that I needed to create a BuiltInDS-based Java testcase and can't use the online testcase.

      It seems that this only happens if setMinFieldWidth(50) is set in ListGrid.setDefaultProperties() and not if it is set in the ListGrid instance itself. How is such a thing possible?

      Code:
      package com.smartgwt.sample.client;
      
      import com.google.gwt.core.client.EntryPoint;
      import com.smartgwt.client.Version;
      import com.smartgwt.client.core.KeyIdentifier;
      import com.smartgwt.client.data.DataSource;
      import com.smartgwt.client.util.Page;
      import com.smartgwt.client.util.PageKeyHandler;
      import com.smartgwt.client.util.SC;
      import com.smartgwt.client.widgets.IButton;
      import com.smartgwt.client.widgets.Window;
      import com.smartgwt.client.widgets.events.ClickEvent;
      import com.smartgwt.client.widgets.events.ClickHandler;
      import com.smartgwt.client.widgets.grid.ListGrid;
      import com.smartgwt.client.widgets.layout.VLayout;
      
      public class BuiltInDS implements EntryPoint {
          private VLayout mainLayout;
          private IButton recreateBtn;
      
          public void onModuleLoad() {
              ListGrid lg = new ListGrid() {
                  {
                      setMinFieldWidth(50);
                  }
              };
              ListGrid.setDefaultProperties(lg);
      
              KeyIdentifier debugKey = new KeyIdentifier();
              debugKey.setCtrlKey(true);
              debugKey.setKeyName("D");
      
              Page.registerKey(debugKey, new PageKeyHandler() {
                  public void execute(String keyName) {
                      SC.showConsole();
                  }
              });
      
              mainLayout = new VLayout(20);
              mainLayout.setWidth100();
              mainLayout.setHeight100();
      
              recreateBtn = new IButton("Recreate");
              recreateBtn.addClickHandler(new ClickHandler() {
                  @Override
                  public void onClick(ClickEvent event) {
                      recreate();
                  }
              });
              mainLayout.addMember(recreateBtn);
              recreate();
              mainLayout.draw();
          }
      
          private void recreate() {
              Window w = new Window();
              w.setWidth("95%");
              w.setHeight("95%");
              w.setMembersMargin(0);
              w.setModalMaskOpacity(70);
              w.setTitle(" (" + Version.getVersion() + "/" + Version.getSCVersionNumber() + ")");
              w.setTitle("setMinFieldWidth(50) problem with ListGrid.setDefaultProperties(lg)" + w.getTitle());
              w.setShowMinimizeButton(false);
              w.setIsModal(true);
              w.setShowModalMask(true);
              w.centerInPage();
      
              final ListGrid employeesGrid = new ListGrid();
              employeesGrid.setDataSource(DataSource.get("employees"));
              // employeesGrid.setMinFieldWidth(50);
              employeesGrid.setAutoFetchData(true);
              employeesGrid.setHeight100();
              employeesGrid.setCanEdit(true);
              employeesGrid.setShowFilterEditor(true);
              employeesGrid.setShowRowNumbers(true);
              w.addItem(employeesGrid);
              w.show();
          }
      }
      Best regards
      Blama

      Comment


        #4
        Setting minFieldWidth via defaultProperties is not really valid since framework features that use ListGrids may rely on the default. For this kind of setting, if you want to use a non-default setting pervasively, create a subclass of ListGrid and use it everywhere.

        Since the FilterEditor is itself just another ListGrid, probably your setting of minFieldWidth interferes with the sizing algorithms there.

        Comment


          #5
          Hi Isomorphic,

          thanks, I did not expect this - good to know.
          I slowly have the feeling that in the end everything is a ListGrid :)

          Any other setter here I should not use in setDefaultProperties():
          Code:
                  ListGrid lg = new ListGrid() {
                      {
                          if (Browser.getIsTablet()) {
                              setSelectionType(SelectionStyle.SINGLE);
                          }
          
                          setAutoFitFieldsFillViewport(true);
                          setShowClippedValuesOnHover(true);
                          setAutoFitWidthApproach(AutoFitWidthApproach.BOTH);
                          // Not I18nEdited, as this would require loading SettingsCache and this is not possible before ServletLogin has returned data
                          setWarnOnRemovalMessage(i18n.removeRecordQuestion());
                          // Wastes a bit of space, but will get rid of all zoom related ListGrid flickering. If the vertical scrollbar is always shown, showing a
                          // horizontal one can not trigger it, possibly ending in a resize/reflow/redraw loop.
                          setLeaveScrollbarGap(true);
          
                          setCanMultiGroup(false);
                          setCanEdit(false);
                          setShowFilterEditor(false);
                          setCanFreezeFields(false);
                          setCanReorderFields(false);
                          setCellHeight(30);
                          setHeaderHeight(37);
                          setWrapHeaderTitles(true);
                          setFixedRecordHeights(true);
                          setHoverDelay(defaultHoverDelay);
                          setHoverWidth(defaultHoverWidth);
                          setRemoveIcon(Lms.imagePath + "/fontAwesome/solid/minus-circle_Red.png");
                          setSelectHeaderOnSort(false);
                          setMinFieldWidth(50);
                          setRemoveFieldProperties(new ListGridField() {
                              {
                                  setWidth(24);
                              }
                          });
                          // See https://forums.smartclient.com/forum/technical-q-a/260630-12-0p-exportclientdata-column-width-problems-with-xlsx-export
                          setExportFieldWidths(true);
                          setExportWidthScale(0.25);
                      }
                  };
                  ListGrid.setDefaultProperties(lg);
          Thank you & Best regards
          Blama

          Comment


            #6
            Many of those would be invalid.

            You can see us re-using ListGrids as parts of other components (eg the PickList) but also in many built-in dialogs (hilite editor, advanced field picker, etc). When you turn off features like field reordering, or frozen fields, you could break how those dialogs, or future built-in dialogs, are meant to work. You're also messing around with default auto-sizing, again, built-in features may rely on default sizing rules, and rely on the faster performance of non auto-sizing fields. Similarly with forcing fixed record heights. And so on..

            Basically, you need to stick to things that strictly affect appearance, the kinds of settings established or changed by skins. For anything else, create and use a standard ListGrid subclass in your code.

            We have to ask though: are you seriously turning off reordering and frozen columns everywhere? Why cripple the grid that way?

            Comment

            Working...
            X