Filter column create with Template

Hello.

I have two questions concerning the filtration and the grid template.

First, is it possible to have the filtration icon when the content of a column is filled via the Template.

Secondly, is it possible to make a filter on the label due <a> and not on the content of the rel='nofollow' href?

Below is the code I use to generate my table.


@if (Model.ListeAllDossiers.Count > 0)

{

    @Html.EJS().Grid("FilterMenu").DataSource(@Model.ListeAllDossiers).AllowFiltering().AllowSorting().Columns(col =>

    {

        col.HeaderText("File").Template("#templateAdmin").Width("120").TextAlign(TextAlign.Left).Add();

        col.HeaderText("People 1").Template("#templatePeople1").Width("120").TextAlign(TextAlign.Left).Add();

        col.HeaderText("People 2").Template("#templatePeople2").Width("120").TextAlign(TextAlign.Left).Add();

        col.Field("CreatedDate").HeaderText("Created").Width("150").TextAlign(TextAlign.Left).Add();

    }).AllowPaging(true).PageSettings(page => page.PageSize(10)).FilterSettings(filter => { filter.Type(FilterType.Excel); }).Render()


}


<script id="templateAdmin" type="text/x-template">

    ${if(IsDossierPremium)}

    <a rel='nofollow' href="/Admin/Proc?idFolder=${IdSyncFolder}">${IdSyncFolder}</a>

    ${else}

    ${IdSyncFolder}

    ${/if}

</script>


<script id="templatePeople1" type="text/x-template">

    ${if(IsDossierPremium)}

    <a rel='nofollow' href="/FolderPeople/Proc?idFolder=${IdSyncFolder}&idEpoux=${IdPremierEpoux}">${IdPeople1}</a>

    ${else}

    <a rel='nofollow' href="/FolderPeople/Lancement?idFolder=${IdSyncFolder}&idEpoux=${IdPremierEpoux}">${IdPeople1}</a>

    ${/if}

</script>


<script id="templatePeople2" type="text/x-template">

    ${if(IsDossierPremium)}

    <a rel='nofollow' href="/FolderPeople/Proc?idFolder=${IdSyncFolder}&idEpoux=${IdSecondEpoux}">${IdPeople2}</a>

    ${else}

    <a rel='nofollow' href="/FolderPeople/Lancement?idFolder=${IdSyncFolder}&idEpoux=${IdSecondEpoux}">${IdPeople2}</a>

    ${/if}

</script>


Thanks in advance for the answers.


3 Replies

SK Sujith Kumar Rajkumar Syncfusion Team August 25, 2021 10:24 AM UTC

Hi Chaffois, 

Greetings from Syncfusion support. 

Based on the queries we could understand that your requirement is to perform filtering on the template column. We would like to let you know that the Grid’s filtering functionality works on basis of comparing the filtered value with the corresponding column field data in the underlying data source bound to the grid and displays the result accordingly. So even if you have customized the values displayed in a column cell using template, the filtering action will be performed based on the field value in the data. This is the default behavior of the Grid. 

So for performing filtering in your case, we suggest you to specify the required field to the template column based on which you need the filter to be performed and specify the row data value in the template. 

We have prepared a sample based on this for your reference. You can find it below, 



If we misunderstood your query or if you require any further assistance, then please get back to us. 

Regards, 
Sujith R 



CQ Chaffois Quentin August 25, 2021 12:17 PM UTC

Hello

Thanks for the example and the answer provided it works correctly now.

Quentin



SK Sujith Kumar Rajkumar Syncfusion Team August 26, 2021 09:31 AM UTC

Hi Quentin, 

You’re welcome. We are glad to hear that your query has been resolved. 

Regards, 
Sujith R 


Loader.
Up arrow icon