Grid Adding Active Delete (Delete Undelete) to a Grid - serenity-is/Serenity GitHub Wiki

Updated to match formatting of most current version. Version 8.8.1.0


Splitted the cheat sheet of Wesley Huang into more specific parts for easier finding the topics.


Adding Active Delete (Delete/Undelete) to a Grid

Being able to add active delete/undelete is simple. Add an "IsActive" Int16 field to the table you wish to use active delete on and then do the following:

On Row.cs add

[ConnectionKey("Default"), TableName("[tbl].[xyz]"), DisplayName("Entries"), InstanceName("Entry"), TwoLevelCached]
[ReadPermission("Administration:General"), ModifyPermission("Administration:General")]
public sealed class xyzRow : Row, IIdRow, INameRow, IIsActiveRow, IIsActiveDeletedRow //<---
{
    //...
    
    [DisplayName("Is Active"), NotNull, Insertable(false), Updatable(true)]
    public short? IsActive { get => fields.IsActive[this]; set => fields.IsActive[this] = value; } //<--- 

    Int16Field IIsActiveRow.IsActiveField{get => fields.IsActive; } //<---      
    //...

    public class RowFields : RowFieldsBase
    {
        //...
        public Int16Field IsActive; //<---
        //...
    }
}

Duplicate the xyzDeleteHandler.cs from the module's RequestHandlers folder and rename to xyzUndeleteHandler.cs. Update all "delete" references to "undelete"

using Serenity.Services;
using MyRequest = Serenity.Services.UndeleteRequest; //<---
using MyResponse = Serenity.Services.UndeleteResponse; //<---
using MyRow = xyzProject.xyzDB.xyzRow;

namespace xyzProject.xyzDB;

public interface IxyzUndeleteHandler : IUndeleteHandler<MyRow, MyRequest, MyResponse> { } //<--- 2 references in this line

public class xyzUndeleteHandler : UndeleteRequestHandler<MyRow, MyRequest, MyResponse>, IxyzUndeleteHandler //<--3 references in this line
{
    public xyzUndeleteHandler(IRequestContext context) //<---
            : base(context)
    {
    }
}

On Endpoint.cs add

 [HttpPost, AuthorizeDelete(typeof(MyRow))]
 public UndeleteResponse Undelete(IUnitOfWork uow, UndeleteRequest request,
       [FromServices] IxyzUndeleteHandler handler)
 {
     return handler.Undelete(uow, request);
 }

On Grid.tsx add

@Decorators.registerClass('xyzProject.xyzDB.xyzGrid')
export class xyzGrid extends EntityGrid<xyzRow> {
    protected getIsActiveProperty() { return xyzRow.isActiveProperty; } //<---
    protected getColumnsKey() { return xyzColumns.columnsKey; }
    //....
    }
}

Don't forget to update the "xyz" to your appropriate references.

⚠️ **GitHub.com Fallback** ⚠️