10

There is InputField in mma but how to make InputTable? In MathCAD it`s possible to insert Excel spreadsheet with input and output variables.Input variables I use for filling of header row and column and output variable for output. How to make the same functionality in mma? Thanks in advance

Igor Fomenko
  • 573
  • 3
  • 13
  • Thanks for the accept, but there's no need for speed. It's better to give it a few hours or even days, so that more answers come in. – Sjoerd C. de Vries Sep 16 '12 at 15:15
  • This MathCAD feature is very good but nothing like it exists built in to Mma. The closest is TableView which @SjoerdC.deVries has shown below. It is undocumented and falls way short of the MathCAD implementation. Fingers crossed for a full documented and better version for V9. – Mike Honeychurch Sep 16 '12 at 22:46

1 Answers1

12
nrows = 3; ncols = 4;
t = ConstantArray[0, {nrows, ncols}];
it = Table[With[{i = i, j = j}, InputField[Dynamic[t[[i, j]]]]], {i,nrows}, {j, ncols}];

Dynamic[TableView[it]]

Mathematica graphics

Another dynamic view to show it works:

Transpose[t] // TableView // Dynamic

(the Transpose here just used to show it actively uses the input).

Mathematica graphics

Please note that I used the undocumented TableView to make it more Excel-like, but I noticed that cell selection is a bit sluggish and/or unpredictable. You may want to change to Grid instead, which seems to work better.

Sjoerd C. de Vries
  • 65,815
  • 14
  • 188
  • 323
  • @NasserM.Abbasi As you can see in the figures it is quite possible to enter data in all the rows (I work on the same platform as you), but there is a good reason for my advice to use Grid. – Sjoerd C. de Vries Sep 16 '12 at 15:12
  • 3
    Dangerous to rely upon undocumented (even unreliable) TableView. It would be really convenient if TableView were implemented reliably and with documentation in a future Mathematica version, but that's something we cannot count on, of course. So Grid is probably better to use for now. – murray Sep 16 '12 at 15:23
  • But inputed values dissapear after recalculation of notebook?! – Igor Fomenko Sep 16 '12 at 16:27
  • @SergeyFomin Did you notice the line: t = ConstantArray[0, {nrows, ncols}]; in the code? What do you think it does? – Sjoerd C. de Vries Sep 16 '12 at 18:30
  • It initialize the array t of course.But I need to keep inputed values.I guess it`s obvious thing or no? – Igor Fomenko Sep 16 '12 at 19:34
  • @SergeyFomin If you want to store data on disk, there are several methods for that. You may want to look up Save, DumpSave, Put, and Write in the documentation. – Sjoerd C. de Vries Sep 16 '12 at 20:54
  • Thanks,but I don`t want to store data on disk in this particular case.May be replace Dynamic with DynamicModule? – Igor Fomenko Sep 17 '12 at 03:36
  • @SergeyFomin If storage isn't your goal, then you just have to prevent that the initialization part is run again. Then the values are available as long as you keep the session running. DynamicModule and SaveDefinitions enable you to have variable contents survive the end of the session, but they write to hard disk as well, of course. – Sjoerd C. de Vries Sep 17 '12 at 07:37
  • How to get local DynamicModule variable x.I can`t find any example in documentation? – Igor Fomenko Sep 17 '12 at 08:48
  • @SergeyFomin You mean from outside the module? You can't. That's why it's called a local variable. You can return its value at the end of a call to the function of course. I'm afraid you really need to read more of the basics in the documentation. – Sjoerd C. de Vries Sep 17 '12 at 13:58
  • Two years left and up to now TableView is undocumented feature.What is happening with super mma system?(( – Igor Fomenko Mar 18 '15 at 05:07
  • I suppose they had other priorities. Mathematica is a very broad system and its expansion is sometimes in areas that I'm not in the least interested in but that are a boon to others. – Sjoerd C. de Vries Mar 18 '15 at 06:27