We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Sorting of a column that uses a custom template

When using a custom template for a column such as this one

<script type="text/x-jsrender" id="colourTemplate">
    {{if Colour && Colour.Name}}
        <div class="colour-preview" style="background-color: {{:Colour.Hex }};"></div>
        {{:Colour.Name}}
    {{/if}}
</script>

How can the sorting of the column be updated so that they are ordered by the 'Name' property? 

does it require adding some comparer function to the Colour object? 

or defining a function to use similar to how you can define custom functions when doing an array sort?


3 Replies

RU Ragavee U S Syncfusion Team June 24, 2014 01:05 PM UTC

Hi Neil

 

We have analyzed your requirement for performing sorting operation in the customTemplate column. As per the behavior, we should not perform filtering, sorting, editing and grouping in Unbound columns. To perform such operations the column must be bound to the grid datasource.

 

Also the sorting operation is performed based on the field property of the column. So if you want to perform sorting to the customTemplate column based on the Name property, please refer the below code snippet.

 

<script type="text/x-jsrender" id="columnTemplate">

    {{if Color && Color.Name}}

        <div style="height:20px;background-color: {{:Color.Hex }};"></div>

        {{:Color.Name}}

    {{/if}}

</script>

 

<script>

$("#Grid").ejGrid({

columns: [                                            

         { field: "Color.Name", headerText: 'Template Column', textAlign: ej.textAlign.Left, width: 100,columnTemplate: true, templateId: "#columnTemplate"},

. . .]

. . .

</script>

 

For your convenience, we have created a simple sample for performing sorting operation on customTemplate column. The sample can be downloaded from the attachment.

 

Please let us know if you need any further assistance.

 

Regards

Ragavee U S



Attachment: Sample_75af1282.zip


NE Neil June 25, 2014 02:27 PM UTC

Thank you that worked.


MS Madhu Sudhanan P Syncfusion Team June 26, 2014 04:51 AM UTC

Hi Neil,

Thanks for your update. Please get back to us if you require further assistance. We will be happy to help you out.

Regards,
Madhu Sudhanan. P

Loader.
Live Chat Icon For mobile
Up arrow icon