How to display multiple items in single cell of each row?
I have this array of data: Products:Array(102)
0:{id:’1’,productDetail:Array(5) > 0:{title:’item-1’,code:’11’}1:{title:’item-2’,code:’12’}} 1:{id:’2’,productDetail:Array(4) > 0:{title:’item-1-1’,code:’11’}…..so on} ….. ….. …..
I want to display in my table one column header as items and display

Hi, could you send a sample of your Products array? Don't need to be the full array only 10 records are fine, with that I can try to reproduce the behavior that you expect.
Hi, could you send a sample of your Products array? Don't need to be the full array only 10 records are fine, with that I can try to reproduce the behavior that you expect.
{ "data": [ { "id": "1", "product": [ { "title": "book-1", }, { "title": "book-2", }, { "title": "book-3", } ], }, { "id": "2", "product": [ { "title": "note-1", }, { "title": "note-1", } ], }, { "id": "3", "product": [ { "title": "pen-1", }, { "title": "pen-2", } ], },{ "id": "4", "product": [ { "title": "copy-1", }, { "title": "copy-2", }, { "title": "copy-1", }, { "title": "copy-2", }, { "title": "copy-1", }, { "title": "copy-2", } ], } { "id": "5", "product": [ { "title": "name-1", }, { "title": "name-2", }, { "title": "name-3", } ], },
] }
id item
will this work? @Ymbere
Hi, could you send a sample of your Products array? Don't need to be the full array only 10 records are fine, with that I can try to reproduce the behavior that you expect.
{ "data": [ { "id": "1", "product": [ { "title": "book-1", }, { "title": "book-2", }, { "title": "book-3", } ], }, { "id": "2", "product": [ { "title": "note-1", }, { "title": "note-1", } ], }, { "id": "3", "product": [ { "title": "pen-1", }, { "title": "pen-2", } ], },{ "id": "4", "product": [ { "title": "copy-1", }, { "title": "copy-2", }, { "title": "copy-1", }, { "title": "copy-2", }, { "title": "copy-1", }, { "title": "copy-2", } ], } { "id": "5", "product": [ { "title": "name-1", }, { "title": "name-2", }, { "title": "name-3", } ], },
] }
id item
![]()
will this work? @Ymbere
I am trying something like below:
const productInfoFormatter =(cell) => { console.log(cell); if(cell.length === 1){ return ( cell[0].title ) }else { cell.map(x => { console.log(x.title) return ( x.title ) }) }
};
it works when cell.length is 1 but not for multiple
Hi @dashName, could you create a Code Box with your code? With that, it's easier to help you.
Hi @dashName, could you create a Code Box with your code? With that, it's easier to help you.
https://codesandbox.io/s/pedantic-allen-i2u7e @Ymbere
Hi, @dashName your implementation is correct you just forgot a return statement, your code will look like this.
const productInfo = (cell, row, rowIndex, formatExtraData) => {
console.log(cell);
if (cell.length === 1) {
return cell[0].title;
} else {
// Return here was missing
return cell.map(x => {
console.log(x.title);
return x.title;
});
}
};
Although you can make the code more clean removing the first if statment
const productInfo = (cell, row, rowIndex, formatExtraData) => {
console.log(cell);
return cell.map(x => {
console.log(x.title);
return x.title;
});
};
Hi, @dashName your implementation is correct you just forgot a
returnstatement, your code will look like this.const productInfo = (cell, row, rowIndex, formatExtraData) => { console.log(cell); if (cell.length === 1) { return cell[0].title; } else { // Return here was missing return cell.map(x => { console.log(x.title); return x.title; }); } };Although you can make the code more clean removing the first
ifstatmentconst productInfo = (cell, row, rowIndex, formatExtraData) => { console.log(cell); return cell.map(x => { console.log(x.title); return x.title; }); };
to display something like like can we add a condition to check the length of array and if the length is > 2 can display + rest of items?
Hi, @dashName your implementation is correct you just forgot a
returnstatement, your code will look like this.const productInfo = (cell, row, rowIndex, formatExtraData) => { console.log(cell); if (cell.length === 1) { return cell[0].title; } else { // Return here was missing return cell.map(x => { console.log(x.title); return x.title; }); } };Although you can make the code more clean removing the first
ifstatmentconst productInfo = (cell, row, rowIndex, formatExtraData) => { console.log(cell); return cell.map(x => { console.log(x.title); return x.title; }); };![]()
to display something like like can we add a condition to check the length of array and if the length is > 2 can display + rest of items?
Yes I am able to do this thanks