# How to dynamic update the content of a Table with dynamic rows? [closed]

I worked this way, but it does not work as expected: The rows of the table:

nrows = Slider[Dynamic@n, {0, 5, 1}];


The contents of the table:

info = Dynamic@Table[<|"a" -> "", "b" -> ""|>, {i, n}]


The input form of the table:

dt = Dynamic @ Table[With[{i = i},
<|"a" -> InputField[info[[1]][[i]][["a"]], String],
"b" -> InputField[info[[1]][[i]][["b"]], String]
|>
], {i, n}]


Why haven't the editing been updated to the table's content?

Also, if I predefine the table's rows, then the table will not be dynamic, but if I do not predefine it, the data will lose when shorten the table's rows. The first way is easy, I've already implemented it that way. So what I am really confused of is the second way. How can I implement the input form if I want the data to be forgotten if I shorten n, and at the same time, what I input into the form, the data I input will be dynamic updated in the table? Or, is there a way to define a table with dynamic rows without losing data when shorten the rows by a slider?

• How changing n should affect already existing data? – Kuba Feb 21 '17 at 13:35
• Sorry for late reply. Your question is just another problem I've been encountered with. I found I could only define a 5 row table and then use a dynamic slider to control the input form generated, but I could not change the row number of the table and generate a same length input form at the same time. So could you help me with that also. – cmal Feb 28 '17 at 11:38
• I just want to use a slider to control a table's length and a dynamic form's length where the form presents the table's every element, and the edited value been updated to the table immediately. – cmal Mar 1 '17 at 3:41
• Sure, but you still didn't answered my first comment, what should happen with entries when you shorten n, should they be forgotten? Maybe changing n should always reset the table? – Kuba Mar 1 '17 at 7:27
• Oh, that is a good question. If I predefine the table's rows, then the table will not be dynamic, but if I do not predefine it, the data will lose when shorten the table's rows. The first way is easy, I've already implemented it that way. So what I am really confused of is the second way. How can I implement the input form if I want the data to be forgotten if I shorten n, and at the same time, what I input into the form, the data I input will be dynamic updated in the table? Thanks! – cmal Mar 1 '17 at 10:44

I think you can solve the problem as follows:

Row[{Slider[Dynamic[n], {0, 5, 1}], " n = ", Dynamic[n]}]

Dynamic[
TableForm[
Table[
{
InputField[Dynamic[Evaluate[Symbol["x" <> ToString[i]]]]],
InputField[Dynamic[Evaluate[Symbol["y" <> ToString[i]]]]]
},
{i, 1, n}
]
]
]

Dynamic[
TableForm[
Table[
<|
"x" <> ToString[i] -> Symbol["x" <> ToString[i]],
"y" <> ToString[i] -> Symbol["y" <> ToString[i]]
|>,
{i, 1, n}
]
]
]