Posted 28 August 2019, 7:50 pm EST
Good morning/evening
I was wondering about the best practice to inject extra data to cells.
Given a source as an array of objects, I’m using the method setDataSource to inject data into an instance of the Sheet but I would like to insert more information within every cells.
Let’s say I would like to have something like the below array as per datasource:
var people = [
{name: "Albert", isAdult: false, country: "American", website: "albert.com", info: { value: 'Ranger', extras: { accomplishments: 10, awards: 5, ...}}},
{name: "Alice", isAdult: true, country: "China", website: "alice.com", info: { value: 'Singer', extras: { accomplishments: 1, awards: 15, ...}}},
{name: "Bob", isAdult: false, country: "Canada", website: "bob.com", info: { value: 'Athlete', extras: { accomplishments: 45, awards: 25, ...}}}
];
The info column should display as value just the key value but when selected the cell I would also be able to retrieve more details contained from the extras key.
What’s the best approach? I wouldn’t use infinite loops with the setCell method as it’s too expensive as operation.
Reference to your documentation:
https://help.grapecity.com/spread/SpreadJSWeb/JavascriptLibrary~GcSpread.Sheets.Sheet~setDataSource.html