Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding EditableTable to global scope #2694

Closed
fvaldes33 opened this issue Apr 5, 2018 · 6 comments
Closed

Adding EditableTable to global scope #2694

fvaldes33 opened this issue Apr 5, 2018 · 6 comments

Comments

@fvaldes33
Copy link

fvaldes33 commented Apr 5, 2018

Description

In my use case we are using Google Places API to scrape some images from the web and storing the URLs in a Table field. We are needing to "re init" the table with all the default values in order to use the addRow and deleteRow functionality. It would be nice if the EditableTable class would be available globally.

Current Code:
https://github.com/craftcms/cms/blob/develop/src/templates/_includes/forms/editableTable.html

{% js %}
    new Craft.EditableTable("{{ jsId }}", "{{ jsName }}", {{ jsCols|raw }}, {
        defaultValues: {{ defaultValues ? defaultValues|json_encode|raw : '{}' }},
        minRows: {{ minRows ? minRows : 'null' }},
        maxRows: {{ maxRows ? maxRows : 'null' }}
    });
{% endjs %}

Proposed Code:

{% js %}
    window["{{jsId}}"] = new Craft.EditableTable("{{ jsId }}", "{{ jsName }}", {{ jsCols|raw }}, {
        defaultValues: {{ defaultValues ? defaultValues|json_encode|raw : '{}' }},
        minRows: {{ minRows ? minRows : 'null' }},
        maxRows: {{ maxRows ? maxRows : 'null' }}
    });
{% endjs %}

This way one can say window[tablefieldhandle].addRow() or any of the other methods in that class.

Additional info

  • Craft version: 3.0.1
  • PHP version: 7
  • Database driver & version: mysql
  • Plugins & versions: -
@Anubarak
Copy link
Contributor

Anubarak commented Apr 5, 2018

Can't you as well grab the table html element, select the data attribute to access it? At least that's the way every other garnish extension works. The current solution is a far better approach in my opinion, because this is how plugins usually work

@fvaldes33
Copy link
Author

@Anubarak I believe I have tried that before and did not succeed. The EditableTable class isn't accessible through the data attribute. If I am wrong, would you be able to show me how to accomplish it?

@Anubarak
Copy link
Contributor

Anubarak commented Apr 6, 2018

@fvaldes33 Sorry for my first post, you are totally right, seems like they are missing their this.$table.data('editable', this) in the class.

In this case that would be my feature request in order to access every table data

@carlcs
Copy link
Contributor

carlcs commented Apr 6, 2018

@Anubarak there’s only one or two Craft objects where they do that, make the instance available via jQuery data(). So it‘s rather an exception than something missing here.

Not the first time I come across it, a feature request that implements it on all (major) objects would be sweet. I know little about data() and its cons though, memory usage maybe?

@brandonkelly
Copy link
Member

Starting with the next release, editable tables now register themselves on the table element as .data('editable-table').

Not the first time I come across it, a feature request that implements it on all (major) objects would be sweet. I know little about data() and its cons though, memory usage maybe?

Ideally all the UI component classes would store references like this, but a blanket FR like that would probably never actually get implemented, because it would mean we have to find the time to audit all the component classes. So for now just posting specific needs as their own FRs is better :)

@fvaldes33
Copy link
Author

@brandonkelly - Totally understand. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants