Message Boards Message Boards

GROUPS:

How to use Manipulate to edit a table?

Posted 3 months ago
545 Views
|
3 Replies
|
0 Total Likes
|

I have a quite simple problem: use manipulate to create and edit a table with identifiers in first column and abbreviations in second column. I am new with manipulate and dynamic modules. I have written a code that works.

ClearAll["Global`*"]
low = CharacterRange["a", "g"];
nRows = 4;
abb[r_] := Table[
   ToExpression["R" <> ToString[r] <> low[[i]]] -> low[[i]], {i, 1, 
    Length[low]}];
row[r_] := {ToExpression["Row" <> ToString[r]], 
  ToExpression["R" <> ToString[r] <> "a"], abb[r]}
rec[{id_, abb_, ru_}] := {id, 
  ToExpression[StringTake[ToString[abb], -1]]}
file = Table[row[r], {r, 1, nRows}];
control[{id_, abbr_, rules_}] := {
  InputField[Dynamic[id]],
  PopupMenu[Dynamic[abbr], rules]
  }
Manipulate[
 MatrixForm[Map[rec, file]],
 Grid[Map[control, file]],
 ContinuousAction -> None,
 ControlPlacement -> Left
 ]

But I find it much too complicated. Would there be a more natural way to proceed? Is it possible to avoid using the update button. Thanks

3 Replies
Posted 3 months ago

Check out TableView

Thanks Mike. What I did not find using TableView is how to put controls such as a PopupMenus in the cells of a table.

I have found what I wanted. This was not very complicated.

nRows = 6;
Manipulate[
 MatrixForm[Transpose[{identifier, abbreviation}]],
 {{abbreviation, ConstantArray["a", nRows]}, 
  ControlType -> None}, {{identifier, 
   ConstantArray["Secteur", nRows]}, ControlType -> None}, 
 Dynamic[Grid[Table[With[{i = i},
     {
      InputField[Dynamic[identifier[[i]]]],
      PopupMenu[Dynamic[abbreviation[[i]]], CharacterRange["a", "g"]]
      }], {i, nRows}]]],
 ControlPlacement -> Left]
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract