Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Filter areas in powertools generated code #11815


User avatar
0
alliance225 created

Hello,

I created this:

public class Visa : FullAuditedEntity, IMayHaveTenant { public int? TenantId { get; set; }

 [Required]
 public virtual string Numero { get; set; }

 public virtual DateTime DateObtention { get; set; }

 public virtual DateTime DateValidite { get; set; }
 //File

 public virtual Guid? Fichier { get; set; } //File, (BinaryObjectId)

 public virtual int ProduitId { get; set; }

 [ForeignKey("ProduitId")]
 public Produit ProduitFk { get; set; }

 public virtual int PaysId { get; set; }

 [ForeignKey("PaysId")]
 public Pays PaysFk { get; set; }

} from powertools and it created this view:

<div class="@(await GetContainerClass())"> <div class="card card-custom gutter-b"> <div class="card-body"> <div class="form"> <div class="row align-items-center mb-4"> <div class="col-xl-12">

                    &lt;div class=&quot;my-3&quot;&gt;
                        &lt;div class=&quot;input-group&quot;&gt;
                            &lt;input type=&quot;text&quot; id=&quot;VisasTableFilter&quot; class=&quot;form-control reload-on-change&quot; placeholder=&#39;@L(&quot;SearchWithThreeDot&quot;)&#39; value=&quot;@Model.FilterText&quot;&gt;
                            &lt;button id=&quot;GetVisasButton&quot; class=&quot;btn btn-primary&quot; type=&quot;submit&quot;&gt;&lt;i class=&quot;flaticon-search-1&quot;&gt;&lt;/i&gt;&lt;/button&gt;
                        &lt;/div&gt;
                    &lt;/div&gt;

                &lt;/div&gt;
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;div id=&quot;AdvacedAuditFiltersArea&quot; style=&quot;display: none&quot; class=&quot;row mb-4&quot;&gt;
            &lt;div class=&quot;col-md-12&quot;&gt;

            &lt;/div&gt;

            &lt;div class=&quot;col-md-3&quot;&gt;
                &lt;div class=&quot;my-3&quot;&gt;
                    &lt;label class=&quot;form-label&quot; for=&quot;NumeroFilterId&quot;&gt;@L("Numero")&lt;/label&gt;
                    &lt;input type=&quot;text&quot; class=&quot;form-control reload-on-keyup&quot; name=&quot;numeroFilter&quot; id=&quot;NumeroFilterId&quot;&gt;
                &lt;/div&gt;
            &lt;/div&gt;
            &lt;div class=&quot;col-md-3&quot;&gt;
                &lt;div class=&quot;my-3&quot;&gt;
                    &lt;label class=&quot;form-label&quot; for=&quot;MinDateObtentionFilterId&quot;&gt;@L("DateObtentionRange")&lt;/label&gt;
                    &lt;div class=&quot;input-group&quot;&gt;
                        &lt;input class=&quot;form-control m-input date-picker startDate&quot; type=&quot;text&quot; placeholder=&quot;@L(&quot; MinValue&quot;)&quot; id=&quot;MinDateObtentionFilterId&quot;&gt;
                        &lt;span style=&quot;line-height: 40px;padding: 0 15px 0 15px;&quot;&gt; &mdash; &lt;/span&gt;
                        &lt;input class=&quot;form-control m-input date-picker endDate&quot; type=&quot;text&quot; placeholder=&quot;@L(&quot; MaxValue&quot;)&quot; id=&quot;MaxDateObtentionFilterId&quot;&gt;
                    &lt;/div&gt;
                &lt;/div&gt;
            &lt;/div&gt;
            &lt;div class=&quot;col-md-3&quot;&gt;
                &lt;div class=&quot;my-3&quot;&gt;
                    &lt;label class=&quot;form-label&quot; for=&quot;MinDateValiditeFilterId&quot;&gt;@L("DateValiditeRange")&lt;/label&gt;
                    &lt;div class=&quot;input-group&quot;&gt;
                        &lt;input class=&quot;form-control m-input date-picker startDate&quot; type=&quot;text&quot; placeholder=&quot;@L(&quot; MinValue&quot;)&quot; id=&quot;MinDateValiditeFilterId&quot;&gt;
                        &lt;span style=&quot;line-height: 40px;padding: 0 15px 0 15px;&quot;&gt; &mdash; &lt;/span&gt;
                        &lt;input class=&quot;form-control m-input date-picker endDate&quot; type=&quot;text&quot; placeholder=&quot;@L(&quot; MaxValue&quot;)&quot; id=&quot;MaxDateValiditeFilterId&quot;&gt;
                    &lt;/div&gt;
                &lt;/div&gt;
            &lt;/div&gt;

            &lt;div class=&quot;col-md-3&quot;&gt;
                &lt;div class=&quot;my-3&quot;&gt;
                    &lt;label class=&quot;form-label&quot; for=&quot;ProduitLibelleFilterId&quot;&gt;(@L("Produit")) @L("Libelle")&lt;/label&gt;
                    &lt;input type=&quot;text&quot; class=&quot;form-control&quot; name=&quot;produitLibelleFilter&quot; id=&quot;ProduitLibelleFilterId&quot;&gt;
                &lt;/div&gt;
            &lt;/div&gt;
            &lt;div class=&quot;col-md-3&quot;&gt;
                &lt;div class=&quot;my-3&quot;&gt;
                    &lt;label class=&quot;form-label&quot; for=&quot;PaysLibelleFilterId&quot;&gt;(@L("Pays")) @L("Libelle")&lt;/label&gt;
                    &lt;input type=&quot;text&quot; class=&quot;form-control&quot; name=&quot;paysLibelleFilter&quot; id=&quot;PaysLibelleFilterId&quot;&gt;
                &lt;/div&gt;
            &lt;/div&gt;
            &lt;div class=&quot;col-md-12 mt-5&quot;&gt;
                &lt;button class=&quot;btn btn-secondary btn-sm&quot; id=&quot;btn-reset-filters&quot;&gt;Reset&lt;/button&gt;
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class=&quot;row my-4&quot;&gt;
            &lt;div class=&quot;col-xl-12&quot;&gt;
                &lt;span id=&quot;ShowAdvancedFiltersSpan&quot; class=&quot;text-muted clickable-item&quot;&gt;&lt;i class=&quot;fa fa-angle-down&quot;&gt;&lt;/i&gt; @L("ShowAdvancedFilters")&lt;/span&gt;
                &lt;span id=&quot;HideAdvancedFiltersSpan&quot; class=&quot;text-muted clickable-item&quot; style=&quot;display: none&quot;&gt;&lt;i class=&quot;fa fa-angle-up&quot;&gt;&lt;/i&gt; @L("HideAdvancedFilters")&lt;/span&gt;
            &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class=&quot;row align-items-center&quot;&gt;
            &lt;table id=&quot;VisasTable&quot; class=&quot;table align-middle table-row-dashed fs-6 gy-5 dataTable no-footer&quot;&gt;
                &lt;thead&gt;
                    &lt;tr&gt;
                        &lt;th&gt;&lt;/th&gt;

                        &lt;th&gt;@L("Actions")&lt;/th&gt;
                        &lt;th&gt;@L("Numero")&lt;/th&gt;
                        &lt;th&gt;@L("DateObtention")&lt;/th&gt;
                        &lt;th&gt;@L("DateValidite")&lt;/th&gt;
                        &lt;th&gt;@L("Fichier")&lt;/th&gt;
                        &lt;th&gt;@L("ProduitLibelle")&lt;/th&gt;
                        &lt;th&gt;@L("PaysLibelle")&lt;/th&gt;
                    &lt;/tr&gt;
                &lt;/thead&gt;
            &lt;/table&gt;
        &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;

</div>

in my js i have

listAction: { ajaxFunction: _visasService.getAll, inputFilter: function () { return { //filter: $('#VisasTableFilter').val(), //numeroFilter: $('#NumeroFilterId').val(), filter: $('#VisasTableFilter').val(), numeroFilter: $('#NumeroFilterId').val() ? '' + $('#NumeroFilterId').val() + '' : '',

   minDateObtentionFilter: getDateFilter($('#MinDateObtentionFilterId')),
   maxDateObtentionFilter: getMaxDateFilter($('#MaxDateObtentionFilterId')),
   minDateValiditeFilter: getDateFilter($('#MinDateValiditeFilterId')),
   maxDateValiditeFilter: getMaxDateFilter($('#MaxDateValiditeFilterId')),
   fichierFilter: $('#FichierFilterId').val(),
   //produitLibelleFilter: $('#ProduitLibelleFilterId').val(),
     //paysLibelleFilter: $('#PaysLibelleFilterId').val(),
     produitLibelleFilter: $('#ProduitLibelleFilterId').val() ? '*' + $('#ProduitLibelleFilterId').val() + '*' : '',
     paysLibelleFilter: $('#PaysLibelleFilterId').val() ? '*' + $('#PaysLibelleFilterId').val() + '*' : '',

 };

}, },

and in my service I have

        var filteredVisas = _visaRepository.GetAll()
                    .Include(e => e.ProduitFk)
                    .Include(e => e.PaysFk)
                    .WhereIf(!string.IsNullOrWhiteSpace(input.Filter), e => false || e.Numero.Contains(input.Filter))
                    .WhereIf(!string.IsNullOrWhiteSpace(input.NumeroFilter), e => e.Numero.Contains(input.NumeroFilter))
                    .WhereIf(input.MinDateObtentionFilter != null, e => e.DateObtention >= input.MinDateObtentionFilter)
                    .WhereIf(input.MaxDateObtentionFilter != null, e => e.DateObtention &lt;= input.MaxDateObtentionFilter)
                    .WhereIf(input.MinDateValiditeFilter != null, e =&gt; e.DateValidite >= input.MinDateValiditeFilter)
                    .WhereIf(input.MaxDateValiditeFilter != null, e => e.DateValidite &lt;= input.MaxDateValiditeFilter)
                    .WhereIf(!string.IsNullOrWhiteSpace(input.ProduitLibelleFilter), e =&gt; e.ProduitFk != null && e.ProduitFk.Libelle.ToLower().Contains(input.ProduitLibelleFilter.ToLower()))

.WhereIf(!string.IsNullOrWhiteSpace(input.PaysLibelleFilter), e => e.PaysFk != null && e.PaysFk.Libelle.Contains(input.PaysLibelleFilter));

When I filter Numero, I am able to get correct data but not with ProduitLibelle and PaysLibelle.

Please help


8 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Is ProduitLibelle a special field ? I'm asking because it's value is either * or ENTERED_VALUE*. Could you also share a databas value for ProduitLibelle and value of input.ProduitLibelleFilter when you debug the source code.

    Thanks,

  • User Avatar
    0
    alliance225 created

    Hello, sorry was away for a while.

    No ProduitLibelle is a regular model propertie.

    public class Produit : AuditedEntity, IMayHaveTenant { public int? TenantId { get; set; }

     [Required]
     public virtual string Libelle { get; set; }
    
     [Required]
     public virtual string Code { get; set; }
    
     public virtual bool Sommeil { get; set; }=false;
    
     public virtual double PrixAchat { get; set; }
    
     public virtual int? MoleculeId { get; set; }
    
     [ForeignKey("MoleculeId")]
     public Molecule MoleculeFk { get; set; }
    
     public virtual int? ClasseTherapeutiqueId { get; set; }
    
     [ForeignKey("ClasseTherapeutiqueId")]
     public ClasseTherapeutique ClasseTherapeutiqueFk { get; set; }
    
     public virtual int? CategoryId { get; set; }
    
     [ForeignKey("CategoryId")]
     public Category CategoryFk { get; set; }
    

    }

    public class Pays : AuditedEntity, IMayHaveTenant
    {
        public int? TenantId { get; set; }
    
        [Required]
        public virtual string Libelle { get; set; }
    
        public virtual int ReseauId { get; set; }
    
        [ForeignKey("ReseauId")]
        public Reseau ReseauFk { get; set; }
    
    }
    

    public class Visa : FullAuditedEntity, IMayHaveTenant { public int? TenantId { get; set; }

      [Required]
      public virtual string Numero { get; set; }
    
      public virtual DateTime DateObtention { get; set; }
    
      public virtual DateTime DateValidite { get; set; }
      //File
    
      public virtual Guid? Fichier { get; set; } //File, (BinaryObjectId)
    
      public virtual int ProduitId { get; set; }
    
      [ForeignKey("ProduitId")]
      public Produit ProduitFk { get; set; }
    
      public virtual int PaysId { get; set; }
    
      [ForeignKey("PaysId")]
      public Pays PaysFk { get; set; }
    

    }

    Sample Produit values:

    361 1 ARTEDIAM 400MG CPR B/12 ARTE154 False 40761 NULL NULL 2023-10-28 20:37:48.9148423 NULL NULL NULL 1,82 363 1 ARTEDIAM 75MG/5ML SP F/30ML ARTE156 False 40761 NULL NULL 2023-10-28 20:37:48.9148426 NULL NULL NULL 1,35 364 1 CEVIT VIT C 100MG CPR B/10 CEVI102 False 40766 NULL NULL 2023-10-28 20:37:48.9148427 NULL NULL NULL 0,53 367 1 OXAPEN 500MG CPR B/12 OXAP105 False 42041 NULL NULL 2023-10-28 20:37:48.9148428 NULL NULL NULL 1,6

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @alliance225

    Is it possible to share your solution via email witn [email protected] ? It will be easier to check this by running your app.

    Thanks,

  • User Avatar
    0
    alliance225 created

    Hi, there

    I have sent the project via email.

    The issue is with https://localhost:44302/App/Visas

  • User Avatar
    0
    alliance225 created

    Hello, sorry I am sending again the project because I had some lines commented out while debugging.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Thanks, we received the project. I had a problem for data creation and disabled some of the migrations to run the app. After that, I created sample records to test this case. As you can see in the screenshot below, filtering by "(Produit) Libelle" worked for me. Could you tell me if I'm testing this in a wrong way ?

  • User Avatar
    0
    alliance225 created

    Weird, as you can see, it is not filtering. Maybe because of some migrations?

    I have also sent you the packpac.

    Maybe you can also send me the application with the migrations that were disabled.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    If you mean you have sent the database, I haven't received it. Could you send it again ?

    Thanks,