Subarray/nested array not loading correctly

Subarray/nested array not loading correctly

laissezpasserlaissezpasser Posts: 2Questions: 1Answers: 0

I'm having trouble loading an array that contains a subarray into DataTables correctly. It's structured like this:

I have two semi-working Plunkers that demonstrate what I've tried already.
1) The problem with this first Plunker is that the entire subarray (which contains all of the the x and y values) appears in concatenated form within a single cell of the row in the DataTable that corresponds to the parent row of the main data array.

2) In this second Plunker, also unsuccessful, the problem is that the same x and y values appear for every row.

I've set a bounty for a solution to this problem on Stack Overflow.

What I'm trying to do is get all of the values contained in dataset — specifically, state, record, x, and y — to display correctly in the DataTable. Can anyone demonstrate a solution that would fix one of these Plunkers?

Answers

  • laissezpasserlaissezpasser Posts: 2Questions: 1Answers: 0
    edited December 2017

    Shameless bump + update:

    Still searching for a solution, but in this third updated Plunker, I discovered how to take all of the values contained in the subarray of the parent array's first row, and (incorrectly) map them onto all of the rows of the parent array. Here's an illustration of what's going wrong:

    So, just to be clear, I've got an array of objects that I want to use to populate my table. Each object has a State, a Record and a set of key-value pairs, with a date being the key and a number being the value. What I want to see in the table is Each date(x)-number(y) pair beside their respective State and Record. Instead of the table having 30 rows, as it currently does, the table should instead have 3,270 rows (i.e., 10 states * 3 record codes * 109 dates-number pairs = 3,270 rows).

    Can anyone demonstrate a solution?

  • kthorngrenkthorngren Posts: 21,303Questions: 26Answers: 4,947

    Check out this example

    To get 3270 rows you will need an array of objects with 3270 objects. I created a new loop that builds a variable called tableData2 to build the 3270 objects. This array is then assigned to the Datatable. I didn't worry about any of the formatting you had, just used the raw data.

    Kevin

This discussion has been closed.