I have a Grid (or TableForm) object like this

Grid[{{Ins, Outs}, {a, b}, {c, d}, {e, f}}, Frame -> All]

enter image description here

that I would like to "incrementally reveal" (within a Manipulate) in the sense, for example, that one row at a time is revealed with each click of the Manipulate.

The part giving me trouble is that I want to "fill in" the table from bottom to top, while maintaining the (final) header cells and grid lines throughout each incremental reveal.

I started out by filling the yet-to-revealed entries with white space (until they are revealed). This is fine for small tables like this, but I also need it to work for tables with dozens of rows so I am seeking something more systematic.

Any hints/tips/nudges would be appreciated.

Edit: To clarify, the desired behavior is like this:

one = Grid[{{Ins, Outs}, {, }, {, }, {e, f}}, Frame -> All];
two = Grid[{{Ins, Outs}, {, }, {c, d}, {e, f}}, Frame -> All];
three = Grid[{{Ins, Outs}, {a, b}, {c, d}, {e, f}}, 
  Frame -> All]; 
Manipulate[{one, two, three}[[i]], {i, {1, 2, 3}}]

enter image description here enter image description here enter image description here

  • $\begingroup$ Maybe you just need double InputField with dynamic referrence to rows? I think wider contex is required. $\endgroup$ – Kuba Jul 19 '13 at 21:30
  • $\begingroup$ @Kuba: The entries I'm wanting to reveal to the viewer are not input that the viewer provides (and that seems to be what InputField is for). Instead, the entries are values which have been computed "offline". $\endgroup$ – JohnD Jul 19 '13 at 21:33
  • $\begingroup$ I see, something like this: grid = {{Ins, Outs}, {a, b}, {c, d}, {e, f}}; Manipulate[ Grid[{First@grid, grid[[n]]}, Frame -> All] , {n, 2, Length@grid, 1}] ? $\endgroup$ – Kuba Jul 19 '13 at 21:39
  • $\begingroup$ Or this grid[[;; n]] instead of {First@grid, grid[[n]]}. $\endgroup$ – Kuba Jul 19 '13 at 21:42
  • $\begingroup$ @Kuba post it :-) $\endgroup$ – Mr.Wizard Jul 19 '13 at 21:45

My version:

data = {{Ins, Outs}, {a, b}, {c, d}, {e, f}};

 m = data; m[[2 ;; n]] = {}; Grid[m, Frame -> All],
 {n, Length@data - 1, 1, -1},
 {m, None}

enter image description here

| improve this answer | |
  • $\begingroup$ Is {m, None} only for scoping purposes? (+1) $\endgroup$ – Kuba Jul 19 '13 at 22:51
  • 1
    $\begingroup$ @Kuba Correct. I'll try to find the reference for that and update this comment when I do. That was quick; here it is. I think that answer makes a good case for this being a reasonable practice. $\endgroup$ – Mr.Wizard Jul 19 '13 at 23:25

Edit. Clear version with ConstantArray but I like more the latter with ArrayPad.

                         ConstantArray["", {n - 2, 2}],
                         grid[[n ;;]]
                        }, 1]
                , Frame -> All]
           , {n, 2, Length@grid, 1}]

ArrayPad seems to fit this job best :)

grid = {{Ins, Outs}}~Join~Partition[CharacterRange["a", "z"], 2];

           Grid[{First@grid}~Join~ ArrayPad[Rest@grid[[n ;;]],
                                            {{n - 1, 0}, 0}, ""], 
                Frame -> All], 
            {n, 1, Length@grid - 1, 1}]

enter image description here

And the SetterBar version analogical as OP's.

           Grid[{First@grid}~Join~ArrayPad[Rest@grid[[Length[grid] - n ;;]],
                                           {{Length[grid] - n - 1, 0}, 0}, ""],
                Frame -> All], 
           {n, Range[Length[grid] - 1], SetterBar}]

enter image description here

| improve this answer | |
  • $\begingroup$ Ok, with that edit and then {n, Length@grid - 1, 1, 1}, it does what I as looking for. Thanks. I will leave it open for a little while to encourage other answers. $\endgroup$ – JohnD Jul 19 '13 at 22:00
  • $\begingroup$ @JohnD I've fixed this :) just a second ago :) $\endgroup$ – Kuba Jul 19 '13 at 22:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.