Concat Two Fields in One Column

I have two fields but i want to put  in a column so, how can i do this?  

3 Replies

MF Mohammed Farook J Syncfusion Team June 19, 2018 01:58 PM UTC

Hi Breno, 

We have achieved your requirement by using ‘ValueAccessor’ property of Grid.  The valueAccessor is used to access/manipulate the value of display data. You can achieve custom value formatting by using the valueAccessor. Please find the code example. 



@Html.EJS().Grid("DefaultFunctionalities").DataSource((IEnumerable<object>)ViewBag.dataSource).Columns(col => 
    { 
 
        col.Field("EmployeeID").HeaderText("Employee ID").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Width("120").Add(); 
        col.Field("FirstName").HeaderText("Full Name").Width("150").ValueAccessor("valueAccess").Add(); 
 
    }).Render() 
</div> 
<script> 
    function valueAccess(field, data, column) { 
        return data[field] + '-' + data['LastName']; 
    } 
 
</script> 



Please find the documentation for your reference. 


Regards, 
J Mohammed Farook 



BL Breno Laustidio replied to Mohammed Farook J June 20, 2018 02:01 PM UTC

Hi Breno, 

We have achieved your requirement by using ‘ValueAccessor’ property of Grid.  The valueAccessor is used to access/manipulate the value of display data. You can achieve custom value formatting by using the valueAccessor. Please find the code example. 



@Html.EJS().Grid("DefaultFunctionalities").DataSource((IEnumerable<object>)ViewBag.dataSource).Columns(col => 
    { 
 
        col.Field("EmployeeID").HeaderText("Employee ID").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Width("120").Add(); 
        col.Field("FirstName").HeaderText("Full Name").Width("150").ValueAccessor("valueAccess").Add(); 
 
    }).Render() 
</div> 
<script> 
    function valueAccess(field, data, column) { 
        return data[field] + '-' + data['LastName']; 
    } 
 
</script> 



Please find the documentation for your reference. 


Regards, 
J Mohammed Farook 


Hi Mohammed Farook J, May you send me a working example, because I could not make it work on my project. 

Thank you.

By Breno Laustidio.


MF Mohammed Farook J Syncfusion Team June 21, 2018 05:08 AM UTC

Hi Breno,  
 
We have prepared a sample based on your requirement and you can downloaded from the following link 
 
 
 
Regards, 
J Mohammed Farook 


Loader.
Up arrow icon