Second try: create a table within a record

  • 0
  • 1
  • Question
  • Updated 4 years ago
  • Answered

I'm continuing my question from another thread (https://quickbase-community.intuit.com/questions/1216894-how-can-i-use-a-formula-field-to-create-a-t...)


When viewing a record, I would like 40 of the data points to be displayed in table format. I'm trying to make use of the image onload technique for these purposes but am missing some critical instructions to bring it to fruition. Can anyone point me in the direction of what the code on my page and in my formula-text field should look like?

I'm also open to any other procedure that would produce a table within a record. 

Thanks!

Photo of Taylor

Taylor

  • 52 Points

Posted 4 years ago

  • 0
  • 1
Photo of Rick

Rick

  • 10 Points
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,224 Points 20k badge 2x thumb
I teach a class on Mondays so I will answer this and other accumulated questions tonight / tomorrow.
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,224 Points 20k badge 2x thumb
I used 40 numeric fields and within the view record page I displayed these fields as a table with 8 rows and 5 columns:

Table In Field
https://haversineconsulting.quickbase.com/db/bj92rdpgi?a=dr&rid=4

Pastie Databsase
https://haversineconsulting.quickbase.com/db/bgcwm2m4g?a=dr&rid=455


Notes:

(1) Within the view view record page in the place where the the image onload field [-] is positioned I replaced it with the generated table.

(2) Mustache was used to generate the markup for the table using a template saved in the following user defined page template.html:

https://haversineconsulting.quickbase.com/db/bj92rdpfr?a=dbpage&pagename=template.html


You should look at the HTML source of this page to see the template

(3) The technique is very general purpose. You just have to change the template.html if you want another layout for the table - perhaps with column headings, or a different number of rows and columns.
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,224 Points 20k badge 2x thumb
I think what the OP wanted was a more compact display of the 40 fields within a view of a record. A native report is going to display each field in a new column.
Photo of Taylor

Taylor

  • 52 Points
Dan, this is amazing! Thank you so much for your help. 2 follow-ups if you don't mind:

1. I can hardcode values but I'm unable to pull data from the specific field name. I've tried
 <td>field name</td>, <td>[field name]</td>, and <td>{{field name}}</td>. Do you know what I did wrong here?

2. Your pastie notes say to leave your contact info in the footer...is that the footer of the code pages or the footer of the database?

Many, many thanks!
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,224 Points 20k badge 2x thumb
1) You need to change (1) the template using <td>{{field name}}</td> but you also need to change (2) the data object so that it has keys corresponding to your field names. As I wrote it I used field names f01, f02 ... f40 in both the template and data object. See this post for examples of using Mustache.

http://coenraets.org/blog/2011/12/tutorial-html-templates-with-mustache-js/

2) If you don't put my contact info into the footer of the code I will sic the Insane Clown Posse on you:

https://www.youtube.com/watch?v=cb1uY22WkOc
Photo of Taylor

Taylor

  • 52 Points
I might be misunderstanding the term "data object".  I have <td>{{kWSavings}}</td> to correspond to my QuickBase field kWSavings. Is that wrong? Or did I miss a step somewhere else?
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,224 Points 20k badge 2x thumb
The variable named "data" in the code has to have keys named after you field labels with some conversions. While the code uses the tag names in the XML response they will differ from the QuickBase field label as the tag names are lowercase with special characters substituted with "_".Try using {{kwsavings}}.
Photo of Taylor

Taylor

  • 52 Points
Brilliant! And so well explained.

PS. Insane clown posse is definitely going to give me nightmares.
Photo of Ryan

Ryan

  • 88 Points 75 badge 2x thumb
I'm very intruiged by the iol technique, but have never used it.  Is there a reason why, in this case, you wouldn't just create a field that is a Formula - Text field, check the box to "Allow some HTML tags", then create the table using HTML and field names from within that field?

Almost all of the fields I create get created twice... once for the data and again as a Formula - Text field with HTML wrapped around it to create hyperlinks, coloring, mouseover tooltip text, various font sizes and types, etc.
Photo of Ryan

Ryan

  • 88 Points 75 badge 2x thumb
Create a field that is a Formula - Text field, edit the properties of that field to check the box to "Allow some HTML tags", then create a psuedo table using HTML and field names from within that field.



Ex:

" | " & [Field 1]   & " | " & [Field 2]   & " | " & [Field 3]   & " | " & [Field 4]  & " | "  & [Field 5]   & " | <hr>" &

" | " & [Field 6]   & " | " & [Field 7]   & " | " & [Field 8]   & " | " & [Field 9]  & " | "  & [Field 10]  & " | <hr>" &

" | " & [Field 11] & " | " & [Field 12] & " | " & [Field 13] & " | " & [Field 14] & " | " & [Field 15] & " | <hr>" &

" | " & [Field 16] & " | " & [Field 17] & " | " & [Field 18] & " | " & [Field 19] & " | " & [Field 20] & " | <hr>" &

" | " & [Field 21] & " | " & [Field 22] & " | " & [Field 23] & " | " & [Field 24] & " | " & [Field 25] & " | <hr>" &

" | " & [Field 26] & " | " & [Field 27] & " | " & [Field 28] & " | " & [Field 29] & " | " & [Field 30] & " | <hr>" &

" | " & [Field 31] & " | " & [Field 32] & " | " & [Field 33] & " | " & [Field 34] & " | " & [Field 35] & " | <hr>" &

" | " & [Field 36] & " | " & [Field 37] & " | " & [Field 38] & " | " & [Field 39] & " | " & [Field 40] & " | <hr>"
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,224 Points 20k badge 2x thumb
> Is there a reason why, in this case, you wouldn't just ...

Because native QuickBase will not allow you to use table tags such as <table>, <tr>, <td> etc. The allowed set of html tags is extremely limited and many of the allowed tags are of no use practical use (eg <var>, <kbd>, <samp>), are now deprecated (eg <font>, <u>) or encourage bad practices (eg <font>). See:

 https://www.quickbase.com/help/default.html#html_text_fields.html

Another reason why you should use the image onload technique is that it is the universal solution as it always works. In fact I advocate that (until QuickBase comes up with a supported solution for introducing JavaScript into QuickBase pages) you should always include an image onload field in every table and treat it as if it was a built in field.

>Almost all of the fields I create get created twice ...

I am not sure what explicit point you are making here but I find tables get crowded with extraneous formula fields that do minor reformatting and presentation of other data bearing fields. In my opinion the presentation aspects of these formula fields should be migrated to forms and reports so that the tables has fewer formula fields and presentation features can be managed through the report and form definitions.
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,224 Points 20k badge 2x thumb
Unfortunately QuickBase does not allow these HTML tags. But it is short work to take your formula convert it and store it as a template in a user defined page and use Mustache's (or Underscores's) templating to generate the HTML.

view-source:https://haversineconsulting.quickbase.com/db/bj92rdpfr?a=dbpage&pagename=template.html
Photo of Ryan

Ryan

  • 88 Points 75 badge 2x thumb
> Because native QuickBase will not allow you to use table tags such as <table>

Good point.  I really should have known this.

> I find tables get crowded with extraneous formula fields

Amen to that.

> In my opinion the presentation aspects of these formula fields should be migrated to forms and reports so that the tables has fewer formula fields

Oh if it were that easy...  Are you referring to the wish-upon-a-star desire for QuickBase to allow for advanced formatting in reports and forms?  Because the lack of such features is what pushes me to use the zillions of formula fields.