ToDataSourceResultAsync - Pivot Table Problem

0 Answers 35 Views
Checkbox DropDownList Grid
Ingenico
Top achievements
Rank 1
Ingenico asked on 20 Aug 2024, 07:37 AM

Hello,

Im using angular 16 and .net core 7 version. When i send request to back-end, i can handle. But i have a problem.

Let's assume we have two tables: roles and users. In Angular, there's a grid where I display the roles. I'm having issues on the backend side when applying filtering in that grid.

 <kendo-grid-column [width]="300" title="Rol" [sortable]="cantFilterandSort" field="Roles">
            <ng-template kendoGridFilterCellTemplate let-filter let-column="column">
                <kendo-multiselect [checkboxes]="true" [autoClose]="false" [tagMapper]="tagMapper"
                    [data]="this.roleList" textField="name" valueField="idx"
                    [valuePrimitive]="true"  (valueChange)="onRoleFilterChange($event)"></kendo-multiselect>
            </ng-template>
        </kendo-grid-column>

onRoleFilterChange(selectedRoles: any[]): void {
    this.state.filter = {
      logic: 'and',
      filters: selectedRoles.map(role => ({
          field: 'Roles',
          operator: 'eq',
          value: role
      }))
  };
    this.getAllData();
  }

The request is reaching the back-end.

[HttpPost]
public async Task<IActionResult> GetAllUser([DataSourceRequest] DataSourceRequest filter)
{
    var result = await this.userService.GetAllUser(filter);
    return CreateActionResultInstance(result);
}


public async Task<DataSourceResult> GetAllUser(DataSourceRequest filter)
{

    var result = await entity
          .AsNoTracking()
          .IgnoreQueryFilters()
          .Include(y => y.Roles)
          .Select(x => new UserViewModel
          {
              Idx = x.Idx,
              Email = x.Email,
              Name = x.Name,
              Phone = x.Phone,
              Surname = x.Surname,
              UserName = x.UserName,
              Roles = x.Roles.Select(x => x.Idx)
          }).ToDataSourceResultAsync(filter);
    return result;}

What I need here is for the filtering to work when a role is selected as a filter in the user list on the screen. How can we use a many-to-many table in this case? I researched a lot but couldn't find anything online.

As a note, the IDs of the roles are of type GUID.

Thanks :)



No answers yet. Maybe you can help?

Tags
Checkbox DropDownList Grid
Asked by
Ingenico
Top achievements
Rank 1
Share this question
or