Announcement

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

    How does showIf in a ListGridField work?

    I'm getting desperate, because the showIf() functionality of ListGridFields isn't working as I expected.

    I have a grid based on a data source:

    Code:
    this.dataSource = isc.RestDataSource.create({
      fields: [
        {name: 'period', canEdit: false, type: 'integer', width: 60},
        ...
      },
      ...
    });
    
    this.grid = isc.ListGrid.create({
      _showAllFields: false,
      dataSource: this.dataSource,
      fields: [
        {name: 'period', showIf: 'console.log(list); return list._showAllFields;'}
      ],
      useAllDataSourceFields: true,
      ...
    });
    Reading the reference, it says showIf is a void() method. I would have expected an boolean method, but okay.

    I have a checkbox in my screen, toggling the value of list._showAllFields. In its "changed" callback, if does this and calls grid.refreshFields(). After the first toggle, this value becomes true. After that I don't see any logging of my showIf-method. Leaving the "return" out, helps and the logging continues to show, but the field's visibility is not toggled.

    What am I doing wrong? Or... how would somebody else dynamically show and hide fields in a grid. I have it working with showField and hideField, but this means a lot of method calls (for quite some fields) and separate calls for showing and hiding. I was hoping to save code by using showIf on the grid fields and calling refreshFields() on the grid.

    #2
    You're correct that showIf should return integer. The docs have been corrected.

    A possible explanation for the behavior you're seeing is that console.log() crashes. Try using SmartClient logging (isc.Log.logWarn() for example). If you're still seeing an issue where showIf does not appear to called when you run refreshFields(), try isolating the behavior to a test case - this may reveal the actual problem, but if it appears to be a bug in SmartClient, please post the test case.

    Comment


      #3
      I also see this void method in FormItem's showIf, that I have used with success before. I'm using a normal function there that returns a boolean (because I think it's a boolean and not an integer).

      I will try to make an isolated test case.

      Comment

      Working...
      X