0
sbenfares created
Hi,
I would like to implement a datatable page with a checkbox list filters. (you can check the capture joined).
I'm trying to do this with this jqueryCode :
listAction: {
ajaxFunction: _candidatService.getCandidats,
inputFilter: function () {
return {
metiers: $('#metiersFilter input:checked[name="Metiers"]').map(function () { return $(this).val(); }).get()
};
}
},
It's not working because on the first load my list is empty (no checkbox is checked) and when it's serialized to my inputDto i have an error :
validationErrors: Array(1) 0: {message: "The value '' is invalid.", members: Array(1)}
See my Input Dto :
[CanBeNull] public List<int> Metiers { get; set; }
Any help appreciated.
PS : When i force in code an empty array it's not working too ... bizarre...
listAction: {
ajaxFunction: _candidatService.getCandidats,
inputFilter: function () {
return {
metiers: []
};
}
},
4 Answer(s)
-
0
-
0
Hi,
Could you share your app service method definition ?
-
0
Finally, when i use an int? array it's working...
public class GetCandidatsInput : PagedAndSortedInputDto, IShouldNormalize { public string Filter { get; set; } [CanBeNull] public int?[] Metiers { get; set; } [CanBeNull] public int?[] Statuts { get; set; } public int? PourcentageMini { get; set; } public int? PourcentageMaxi { get; set; } public string Region { get; set; } public void Normalize() { if (string.IsNullOrEmpty(Sorting)) { Sorting = "Name,Surname"; } } }
I don't really understand why...
Here is my AppService code :
public async Task<PagedResultDto<CandidatListDto>> GetCandidats(GetCandidatsInput input) { var query = UserManager.Users .Where(u => u.CandidatId.HasValue) .WhereIf((input.Metiers ?? throw new InvalidOperationException()).Any(x=>x.HasValue) , u => input.Metiers.Contains(u.Candidat.MetierCode)) .WhereIf((input.Statuts ?? throw new InvalidOperationException()).Any(x => x.HasValue), u => input.Statuts.Contains(u.Candidat.StatutInscriptionCode)) .WhereIf(input.PourcentageMini.HasValue, u => u.Candidat.PourcentageCompletudeProfil >= input.PourcentageMini.Value) .WhereIf(input.PourcentageMaxi.HasValue, u => u.Candidat.PourcentageCompletudeProfil <= input.PourcentageMaxi.Value) .WhereIf(!input.Region.IsNullOrWhiteSpace(), u => u.Candidat.Adresse.Region.Equals(input.Region)) .WhereIf( !input.Filter.IsNullOrWhiteSpace(), u => u.Name.Contains(input.Filter) || u.Surname.Contains(input.Filter) || u.UserName.Contains(input.Filter) || u.PhoneNumber.Contains(input.Filter) || u.EmailAddress.Contains(input.Filter) ); var candidatsCount = await query.CountAsync(); var candidats = await query .OrderBy(input.Sorting) .PageBy(input) .Select(x => new CandidatListDto { Id = x.Id, PhotoUrl = x.PhotoUrl.IsNullOrEmpty() ? BlobConsts.Avatars.DefaultImageFilePath : $"{_appConfiguration["App:AzureContainerUrlBase"] + _appConfiguration["App:AzureAvatarContainerName"]}/{x.PhotoUrl}", FullName = x.FullName, CreationTime = x.CreationTime, Statut = StatutInscriptionCandidatsConsts.StatutsInscriptionKeyValuePairs.FirstOrDefault(p => p.Key.Equals(x.Candidat.StatutInscriptionCode)).Value, Metier = x.Candidat.MetierAutre.IsNullOrEmpty() ? MetiersConsts.MetiersKeyValuePairs.FirstOrDefault(p => p.Key.Equals(x.Candidat.MetierCode)).Value : x.Candidat.MetierAutre }) .ToListAsync(); var candidatsListDtos = ObjectMapper.Map<List<CandidatListDto>>(candidats); return new PagedResultDto<CandidatListDto>( candidatsCount, candidatsListDtos ); }
-
0
Hi @sbenfares
Have you solved your problem ?