Skip to content

Grid Adding Active Delete (Delete Undelete) to a Grid

Victor Tomaili edited this page May 3, 2021 · 1 revision

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 //<---
{
    //...
    [NotNull, Insertable(false), Updatable(true)]
    public Int16? IsActive //<---
    {
        get { return Fields.IsActive[this]; }
        set { Fields.IsActive[this] = value; }
    }

    Int16Field IIsActiveRow.IsActiveField //<---
    {
        get { return Fields.IsActive; }
    }        
    //...

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

On Repository.cs add

public UndeleteResponse Undelete(IUnitOfWork uow, UndeleteRequest request)
{
    return new MyUndeleteHandler().Process(uow, request);
}
private class MyUndeleteHandler : UndeleteRequestHandler<MyRow> { }

On Endpoint.cs add

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

On Grid.ts add

namespace FMCorpIntranet.Default {
    
    @Serenity.Decorators.registerClass()
    export class EmployeesGrid extends Serenity.EntityGrid<EmployeesRow, any> {
        protected getIsActiveProperty() { return EmployeesRow.isActiveProperty; } //<----
        protected getColumnsKey() { return 'Default.Employees'; }
        //....
    }
}
Clone this wiki locally