Mail: [email protected] Phone: +1(424)231-4091

Add Crud Entry Custom Action

An action helps to perform a request on a crud entry. By default, NexoPOS comes with "edit" and "delete" actions that operate directly on the selected row. This will show you to create a custom action on a crud Entry.

Register Custom Filter

We need to register a filter in order to be able to extend the row actions. This can be made with the following code:

Let's explain what is happening above. First of all, we'll register our filter on the service provider of our module. We've imported 3 classes (Hook, CrudEntry, and OrderCrud).

In this example, we're trying to add a new action to a crud entry on the order table. We then add a filter using the method "addFilter" that will but the callback to the method "setActions" of the OrderCrud class.

So everytime the method "setActions" is called, the callback "customAction" is fired with as a unique parameter a "CrudEntry" instance.

Add Action To The CrudEntry Instance

Now, we'll focus on the callback method as that's where we'll inject our action. Note that we can inject more than one action at the time. Here is our to define an action:

Note that here, our action will have as identifier "email" and as a label "Email to Customer" (visible by the user). When it's clicked, a GET request (asynchronous will be performed) to the URL provided on the "url" parameter.

In case you want the user to confirm his action, you can add a new entry on that array named "confirm" like so:

For asynchronous requests only "GET" and "DELETE" are supported. If you would like the user to land on a different page after clicking on the action, you'll use as a type "GOTO" instead of "GET" like this:

By clicking on an action, the user will be redirected to the page on the "url" key.