Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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

share|improve this question
    
Maybe you just need double InputField with dynamic referrence to rows? I think wider contex is required. –  Kuba Jul 19 '13 at 21:30
    
@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". –  JohnD Jul 19 '13 at 21:33
    
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}] ? –  Kuba Jul 19 '13 at 21:39
    
Or this grid[[;; n]] instead of {First@grid, grid[[n]]}. –  Kuba Jul 19 '13 at 21:42
    
@Kuba post it :-) –  Mr.Wizard Jul 19 '13 at 21:45
show 3 more comments

2 Answers

up vote 3 down vote accepted

My version:

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

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

enter image description here

share|improve this answer
    
Is {m, None} only for scoping purposes? (+1) –  Kuba Jul 19 '13 at 22:51
1  
@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. –  Mr.Wizard Jul 19 '13 at 23:25
add comment

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

Manipulate[
           Grid[
                Flatten[{
                         {grid[[1]]},
                         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];

Manipulate[
           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.

Manipulate[
           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

share|improve this answer
    
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. –  JohnD Jul 19 '13 at 22:00
    
@JohnD I've fixed this :) just a second ago :) –  Kuba Jul 19 '13 at 22:01
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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