apostrophecms / apostrophe-documentation

Documentation for the ApostroheCMS open-souce ecosystem
https://docs.apostrophecms.org/
MIT License
25 stars 45 forks source link

[DOCS ISSUE] Page: Custom columns and sortable columns for the "manage" modal #278

Closed adamhowse closed 4 years ago

adamhowse commented 4 years ago

Following the example results in the application crashing to the console with this error:

ReferenceError: self is not defined

Caused by:

return self.partial('manageUpdatedAt.html', { value: value });

I can however get it working by wrapping it in this, which is not consistent with how it should work according to the docs:

  beforeConstruct: function(self, options) {
    options.addColumns = [
      {
        name: 'updatedAt',
        label: 'Last Updated',
        sort: {
          updatedAt: 1
        },
        partial: function(value) {
          if (!value) {
            return '';
          }
          return self.partial('manageUpdatedAt.html', { value: value });
        }
      }
    ].concat(options.addColumns || [])
  }
boutell commented 4 years ago

Correct, you can't use the partial technique in plain old addFields because it has no access to self, this needs addressing in the docs. In 3.0 this issue will go away for... well, several reasons, including a completely new admin UI... but also because self can be made available when configuring fields without as much work.

abea commented 4 years ago

Where in the docs is the confusion coming from?

adamhowse commented 4 years ago

It's coming from this page (following the example code will result in the error, unless using the fix I posted above): https://docs.apostrophecms.org/advanced-topics/advanced-pieces-topics/adding-columns.html

abea commented 4 years ago

I'll put it on my list for "soon", but if you would be willing to submit a PR to the docs we'd really appreciate it.