How i can add dynamic columns for each row in react GridComponnet

Hello Team,

I have an object like this : datasource = [{name:'test',listItems:[{...},{...} ..]


I want to define my gridComponent columns like this: 

name,[listItems]

can somene help me please 


3 Replies

JC Joseph Christ Nithin Issack Syncfusion Team August 31, 2022 07:11 PM UTC

Hi Saidani Yosra,


  Thanks for your update.


  By default, the EJ2 Grid column only supports number, string, date, dateTime, Boolean, checkbox type values, and which does not supports array type value. Refer to the below documentation.


columnType: https://ej2.syncfusion.com/documentation/api/grid/columnType/ 


We can show an array of values in the Grid column using columnTemplate/valueAccessor features. But, this is used only for the display purposes. We cannot perform any Grid actions like Filtering, Sorting, column-spanning, Searching, Grouping, etc., on the array type column. This is the behavior of EJ2 Grid.


So, in your case we suggest the best way is to use comma delimited string and parse it back in the back end.


Please get back to us for further details.


Regards,

Joseph I.




SA saidaniyosra August 31, 2022 07:44 PM UTC

thank you for your reply

 but my question is how i can display columns based on list for each row 

example of the object returned by the api:

{ name,

[

   {'repaired', ...}, 

   {'Not repaired',..} 

   {'NFF',..} 

   {'Product conform,..} 


    ......

] }


my final Grid be like this 


 



Attachment: captures_9fb2af33.rar


PS Pavithra Subramaniyam Syncfusion Team September 1, 2022 10:14 AM UTC

Hi saidaniyosra,


In EJ2 Grid, we can only show the nested objects field if the records have a single object like {name:'test',listItems:{...}} But in your dataSource, the “listItems” has an array of objects which is not supported in our Grid component with default column settings. However, you can display the values using columnTemplate/valueAccessor features. But as we said in our previous update, this is for display purposes only, we cannot do any Grid actions like Filtering, Sorting, column-spanning, Searching, Grouping, etc., on this column. This is the behavior of EJ2 Grid.


Documentation: https://ej2.syncfusion.com/react/documentation/grid/columns/column-template/#using-condition-template

  https://ej2.syncfusion.com/react/documentation/grid/columns/columns/#valueaccessor


sample                : https://stackblitz.com/edit/react-pupj5j?file=index.js


Please get back to us for further details.


Regards,

Pavithra S


Loader.
Up arrow icon