Learn More, Pay Less!
Limited Time Offer!
Open Closed

Cannot extend entity actions #8725


User avatar
0
lilot18 created

ABP Framework Configuration

  • ABP Framework version: v9.0.2
  • UI Type: MVC
  • Database System: PostgreSQL
  • Tiered: Yes

Issue Description

Hello, I need to extend the actions on an entity.
I tried following the steps in the guide, but I can't get it to work:
🔗 ABP Entity Action Extensions Guide

My entity is invoice:

So, I added the following code to the TesoreriaDigitaleWebModule page:

Configure<AbpBundlingOptions>(options =>
{
    options.ScriptBundles.Configure(
        typeof(Pages.Invoices.IndexModel).FullName,
        bundleConfiguration =>
        {
            bundleConfiguration.AddFiles(
                "/Pages/Invoices/my-user-extensions.js"
            );
        });
});

JS:

var clickMeAction = {
    text: 'Click Me!',
    action: function (data) {
        alert("test");
    }
};
abp.ui.extensions.entityActions
    .get('invoice')
    .addContributor(function (actionList) {
        actionList.addTail(clickMeAction);
    });

Additionally, I wanted to know if there's a smarter way (using only the index.js page) to add an action (while still staying within the custom-code blocks).


3 Answer(s)
  • User Avatar
    0
    EngincanV created
    Support Team .NET Developer

    Hi, yes you can use the custom code support to add an entity-action to the data table directly. You can apply the following steps:

    1-) Edit Frontend.Mvc.Page.index.js.txt template and add custom-code block placeholder:

                               //<suite-custom-code-block-10>
                                  //your custom code goes here...
                              //</suite-custom-code-block-10>
    

    2-) Regenerate the same entity, after you do that the placeholder will be added for the related entity, and you can update the content in the placeholder for the related index.js file:

                               //<suite-custom-code-block-10>
                               ,{
                                    text: l("ClickHere"),
                                    action: function (data) {
                                        //define what should happen when to the action clicked
                                    }
                                },
                              //</suite-custom-code-block-10>
    

    3-) Then in the next code generations, ABP Suite will respect your change, and will not override the specified section.


    For further info please refer to the documentation: https://abp.io/docs/latest/suite/customizing-the-generated-code#adding-new-custom-hook-points-changing-their-places-1

    <suite-custom-code-block-10> is just an example placeholder, you can use any number, however, please note that the number should be used only once per page.

  • User Avatar
    0
    lilot18 created

    Hi, thank you very much. I imagine this applies to all entities, but I would like to do it for just one entity.

  • User Avatar
    0
    EngincanV created
    Support Team .NET Developer

    Hi, thank you very much. I imagine this applies to all entities, but I would like to do it for just one entity.

    Hi, when you do this the related placeholder will be applied to all of your index.js files. However, since you will only write your custom code for a single index.js file, the other placeholders will be empty and they will be shown as comment blocks. So, you will be able to write your custom code per file by your choice.

Made with ❤️ on ABP v9.2.0-preview. Updated on February 13, 2025, 10:35