EasyAbp / AbpHelper.CLI

Providing code generation and more features to help you develop applications and modules with the ABP framework.
MIT License
285 stars 95 forks source link

Add data filtering dto for template #188

Closed blackWins closed 1 year ago

blackWins commented 1 year ago

AbpHelper

in CodeGeneration_Crud We can add createGetListInput dto bool option

Application

if createGetListInput true then modify below template: AppService IAppService

MyAppService: CrudAppService<XX, XXDto, Guid, MyGetListInput , CreateUpdateXXDto, CreateUpdateXXDto>
{
    //generated override CreateFilteredQueryAsync method
    protected override async Task<IQueryable<XX>> CreateFilteredQueryAsync(MyGetListInput input)
    {
        // TODO: AbpHelper generated 
        return (await base.CreateFilteredQueryAsync(input));
    }
}

Or we can use autofilterer project package to override the CreateFilteredQueryAsync

Dto

Add MyGetListInput dto

public MyGetListInput:PagedAndSortedResultRequestDto
{
   //entity all properties
   ...
}

UiRazor

Index.cshtml.cs declare

...
public MyGetListInput MyFilter{get;set;}
...

Index.cshtml use dynamic form output MyFilter

...
<abp-dynamic-form abp-model="MyFilter" id="My_Filter" />
...

index.js add

...
    //inputAction
    var getFilter = function () {
        var input = {};
        var formArr =
            JSON.parse(
                JSON.stringify($("#My_Filter").serializeArray())
                    .replace(/MyFilter./g, ''));

        formArr.forEach(function (data) {
            if (data.value != '') {
                input[abp.utils.toCamelCase(data.name)] = data.value;
            }
        })
        return input;
    };

    //listen input
    $("#My_Filter :input").on('input', function () {
        dataTable.ajax.reload();
    });

    var dataTable = $('#MyTable').DataTable(abp.libs.datatables.normalizeConfiguration({
        ...
        ajax: abp.libs.datatables.createAjax(service.getList,getFilter),
        ...
    }));
...
gdlcf88 commented 1 year ago

https://github.com/EasyAbp/AbpHelper.CLI/pull/180