I am working on an Excel-like application, but I am having problems with a multi-dimensional array.
I have array of columns that looks like this:
var columns = [
{A: {binding: "A",header: "A"},
{B: {binding: "B",header: "B"},
{C: {binding: "C",header: "C"}
];
And then I have an array representing the value of every cell that looks like this:
var data = [
{A:"row 0 col A", B: "row 0 col B", C:"row 0 col C"},
{A:"row 1 col A", B: "row 1 col B", C:"row 1 col C"},
{A:"row 2 col A", B: "row 2 col B", C:"row 2 col C"}
];
The binding
property of the objects in the columns
array will be used to get the column's value for each row.
However, I am encountering an issue when inserting a new column in the middle of some alphabetical keys.
Let's say I need a new column between column A
and column B
. The result looks like this:
var columns = [
{A: {binding: "A",header: "A"},
{B: {binding: "B",header: "B"},
{C: {binding: "C",header: "C"},
{D: {binding: "D",header: "D"}
];
It's just pushing the new column onto columns
.
I think I have to insert a new cell/item between all alphabetical keys for every row, and rename all the keys (in this case, rename keys B
to C
, C
to D
, etc).
I would like the result to look like this:
var data = [
{A:"row 0 col A", B:"new col inserted here", C:"row 0 col B", D:"row 0 col C"},
{A:"row 1 col A", B:"new col inserted here", C:"row 1 col B", D:"row 1 col C"},
{A:"row 2 col A", B:"new col inserted here", C:"row 2 col B", D:"row 2 col C"}
];
I'm concerned about performance issues if I were to rename all these keys, especially if I have 120 columns (A-DZ) and 100 rows.
I have two questions:
- What is the most efficient way to do this?
- Will I have performance issues when renaming these keys if I have lots of rows and columns?