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

Vue admin table manually reloading and adjusting query params #13416

Merged
merged 5 commits into from
Jul 14, 2023

Conversation

nfourtythree
Copy link
Contributor

Description

To give greater extensibility and flexibility this PR introduces new properties, methods and events for the Vue admin table.

The ability to reload a table manually (using Craft.VueAdminTable.reload():

const adminTable = new Craft.VueAdminTable({
    // ...
});

// Reload table every 15 seconds
setInterval(function() {
    adminTable.reload();
}, 15000);

The ability to listen to and manipulate the query parameters that are created for the table data endpoint (using the onQueryParams callback):

new Craft.VueAdminTable({
  // ...
  onQueryParams: function(params) { 
    console.log('Query Params:', params); 

    params.foo = 'bar';
    return params; 
  },
  // ...
});

A full (although simplified) example of using this together could be passing a value of a custom text box to the endpoint:

<input type="text" name="foo" value="">
<div id="vue-admin-table"></div>

{% js %}
var columns = [
    { name: '__slot:title', title: 'title'  },
];

const $input = document.querySelector('input[name="foo"]');

const adminTable = new Craft.VueAdminTable({
    columns: columns,
    container: '#vue-admin-table',
    tableDataEndpoint: Craft.getActionUrl('my/custom/endpoint'),
    onQueryParams: function(params) {
        if ($input.value) {
            params.foo = $input.value;
        }
        return params;
    }
 });

 $fooInput.addEventListener('blur', function(ev) {
    adminTable.reload();
 });
{% endjs %}

Related issues

#13389

@nfourtythree nfourtythree self-assigned this Jul 12, 2023
@nfourtythree nfourtythree requested review from benjamindavid and a team as code owners July 12, 2023 09:53
Copy link
Contributor

@timkelty timkelty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No notes. 10/10 Would review again.

@brandonkelly brandonkelly merged commit e1c0d3a into 4.5 Jul 14, 2023
@brandonkelly brandonkelly deleted the feature/admin-table-manual-reload-and-query-params branch July 14, 2023 19:07
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

Successfully merging this pull request may close these issues.

3 participants