Grid grouping - caption format

Hi,

I have grouping in grid. In caption format I'd like to show text from some other fields.

For example, datasource has fields GroupID, GroupName, GroupDate, ItemID, ItemName and ItemAmount.

I'd like to have columns  ItemName and ItemAmount grouped by  GroupID. But in caption format of the group, I'd like to show GroupName and GroupDate for certain GroupID. How can I achieve that?


(we use EJ1)


5 Replies 1 reply marked as answer

PS Pon Selva Jeganathan Syncfusion Team July 16, 2021 08:36 AM UTC

Hi Petra,   
 
Thanks for contacting syncfusion forum. 
 

Query: Grid grouping - caption format : In caption format I'd like to show text from some other fields.

We achieved this requirement by using jsrender helpers. Using jsrender helpers, we can change the name of the field displayed in the Group Caption.

Please refer to the below code snippet,


  
<ej-grid id="FlatGrid" 
         allow-sorting="true" allow-grouping="true" 
         selectiontype="Multiple" datasource="(IEnumerable<object>)ViewBag.datasource" group-settings="@(new GroupSettings { CaptionFormat="#template" })" allow-paging="true" toolbar-click="click"> 
 
    <e-columns> 
….. 
</ej-grid> 
 
<script type="text/x-jsrender" id="template"> 
    <span> 
        {{:~replaceText(#data['field'])}} 
    </span> 
</script> 
<script> 
   var helper = { 
       replaceText: function (field) { 
            var obj = $("#FlatGrid").ejGrid("instance");//create Grid Instance 
           var colIndex = obj.getColumnIndexByField(field) 
           var fieldnames = obj.getColumnFieldNames(); 
           if (fieldnames.length == (colIndex+1)) { 
              return fieldnames[0]; 
           } 
           else { 
               return fieldnames[colIndex + 1]; 
           } 
        } 
    };//helpers 
   $.views.helpers(helper); 
</script> 
  

Please refer to the below screenshot,

Please refer to the below sample,

https://www.syncfusion.com/downloads/support/forum/167280/ze/core2sample2138399938

Please refer to the below API documentation,

https://help.syncfusion.com/api/js/ejgrid#methods:getcolumnfieldnames

https://help.syncfusion.com/api/js/ejgrid#methods:getcolumnindexbyfield

Please get back to us if you need any further assistance.   
 
Regards,   
Pon selva   



PV Petra Visic July 16, 2021 12:33 PM UTC

Hello,


thanks for answer.

Unfortunately, that's not exactly what I wanted.

I'd like to show the name of the group (= the value of field GroupName) for that GroupID, not the text "GroupID" itself.

On your example, that would be:

preuzmi.png



PS Pon Selva Jeganathan Syncfusion Team July 19, 2021 10:52 AM UTC

Hi Petra,   
 
Thanks for the update. 
 

Query: I'd like to show the name of the group (= the value of field GroupName) for that GroupID, not the text "GroupID" itself

We achieved this requirement by using jsrender helpers. Using jsrender helpers, we have changed the caption value based on field and key value.

Please refer to the below code snippet,


  
<ej-grid id="FlatGrid" 
         allow-sorting="true" allow-grouping="true" 
         selectiontype="Multiple" datasource="(IEnumerable<object>)ViewBag.datasource" group-settings="@(new GroupSettings { CaptionFormat="#template" })" allow-paging="true" toolbar-click="click"> 
 
    <e-columns> 
….. 
</ej-grid> 
 
<script type="text/x-jsrender" id="template"> 
    <span> 
{{:~replaceText(#data['field'], #data['key'])}}    </span> 
</script> 
<script> 
   var helper = { 
       replaceText: function (field) { 
            var obj = $("#FlatGrid").ejGrid("instance");//create Grid Instance 
          var data = obj.model.dataSource; 
           for (var i = 0; i < data.length; i++) { 
               if (data[i].GroupID ==key) { 
                   return data[i].GroupName; 
               } 
           } 
    };//helpers 
   $.views.helpers(helper); 
</script> 
  

Please refer to the below screenshot,

Please refer to the below sample,

https://www.syncfusion.com/downloads/support/forum/167280/ze/core2sample_(2)128493439

 
Please get back to us if you need any further assistance.   
 
Regards,   
Pon selva  

Marked as answer

PV Petra Visic July 19, 2021 01:22 PM UTC

Thanks, that's what I wanted.



PS Pon Selva Jeganathan Syncfusion Team July 20, 2021 09:51 AM UTC

Hi Petra,   
 
Thanks for the update. 
 
We are glad to hear your query has been solved by our solution. 
 
Kindly get pack to us for further assistance. We are happy to assist you. 
 
Regards,   
Pon selva    



Loader.
Up arrow icon