7 Replies Latest reply on Mar 27, 2012 5:35 AM by timwhisenant

    Webviewer field to show counters

    psijmons

      I picked this up a few years ago from this forum (can't remember from who) and use it in the footer of all my layouts. It is a very minimal way of showing that the user in in record no.. of ... records in the found set by placing a webviewer, and there is also a visual background bar to give the user an intuitive glance of the record position (see attachment). It doesn't require fields and is portable across layouts. Users in my solution are locked out of the menu bar so the normal FileMaker indicators are not visible.

       

      My question is the following; is there a command I can use to add the total number of records in this webviewer text?

      Thanks in advance,

      Peter

       

       

       

      webviewer.records ( "Record [current] of [found]" ; "*{ font-size: 7pt; font-family: "Lucida Grande", Tahoma, sans-serif; color: White; } #text{ margin-top: 0px ; } body { background-color: Silver; } " ; "DimGrey" )

       

       

      /*

      For a list of possible colors by name use this url

      http://en.wikipedia.org/wiki/Web_colors

       

       

      Use the following in the css parameter to control font size, face and color

      *{ font-size: 9pt; font-family: "Lucida Grande", Tahoma, sans-serif; color: black; }

       

       

      Use the following to control the positioning of the text

      #text {margin-top: 10px; }

       

       

      Set the color to "transparent" to not show the bar

       

       

      Use the following to control the background

      body { background-color: green; }

      */

        • 1. Re: Webviewer field to show counters
          BowdenData

          psijmons wrote:

           

          It is a very minimal way of showing that the user in in record no.. of ... records in the found set by placing a webviewer...   My question is the following; is there a command I can use to add the total number of records in this webviewer text?

          Thanks in advance,

          Peter

           

          webviewer.records ( "Record [current] of [found]" ; "*{ font-size: 7pt; font-family: \"Lucida Grande\", Tahoma, sans-serif; color: White; } #text{ margin-top: 0px ; } body { background-color: Silver; } " ; "DimGrey" )

           

           

          Peter,

           

          This is a custom function you are calling, so you need to modify it to add the additional information. For the total record count, use the "Get ( TotalRecordCount )" function. If desired to fully mimic the menu bar information, you can also add the sort status. Use a case statement to determine this.

           

          Case(

            Get (SortState) = 0 ; " - Unsorted" ;

            Get (SortState) = 1; " - Sorted";

            Get (SortState) = 2; " - Semi-sorted"

          )

           

          Once you add the placeholders to the custom function, your call to it might be something like this:

           

             webviewer.records ( "Record [current] of [found]. Total [total]. ([sortState])."

           

          Note: Two words of caution on using webviewers like this.

           

          1) If using on Windows XP and the background is not white, the webviewer will likely "flash" each time it redraws (such as moving from record to record). I don't know if this is an issue on Windows Vista or 7. It does not seem to be an issue on the Mac.

          2) In databases that are heavily loaded, the webviewer can be a definite performance hit.

           

          HTH.

           

          Doug de Stwolinska

          Bowden Data Services, LLC

          • 2. Re: Webviewer field to show counters
            psijmons

            Thanks Doug, good advice, I wasn't aware that this was a potential perfomance issue. Probably when the users scroll fast with the mouse I can imagine it does.

            ( I rarely check on XP, there are only so many OS's to test, fortunately, my clients are gradually phasing out XP).

             

            with regards,

            Peter

            • 3. Re: Webviewer field to show counters
              timwhisenant

              Hi Peter,

               

               

               

              The source of this technique seems to be Matt Petrowsky, I thought I had seen that dot syntax before. The original code can be found here: https://github.com/petrowsky/fmpfunctions

               

              Thanks Matt.

               

               

               

              Four custom functions work together to make the code work. One needs to be modified to provide additional text to your footer line, the “webviewer.records” custom function.

               

              You have 2 easy choices, first modify the var.found variable element to include the text you desire, i.e.[[ Get(FoundCount) & “   Total Records = “& Get(TotalRecordCount)”]].

               

              Second, you could add to your call statement like so, webviewer.records( “Record [current] of [found]   Total Records = [total] | [percentage]"; ……  and add another line to the substitute statement to include the var.total variable.

               

               

               

              Hope this helps,

               

              Tim

              • 4. Re: Webviewer field to show counters
                psijmons

                hello Tim,

                thanks for the feedback, but there is still a glitch to get it to work. The code from Matt (with thanks) I use is below, which I read as follows:

                var.total is substituted by var.found if there is indeed a subset.

                So I introduced a new var.fullset to be used as a placeholder in the webviewer. However, it does not evaluate correctly, just says

                e.g. Record 47 of 156, Total [fullset]

                 

                I just want this added to the text, not the css grey bar that indicates the record position in the found set.

                Where is the mistake I'm making here?

                 

                 

                 

                 

                /*

                * =====================================================

                * webviewer.records ( format ; css ; color )

                *

                * RETURNS:        (string) Web viewer using formatted string

                * DEPENDENCIES:   webviewer.data(), html.document(), html.css()

                * NOTES:          Available placeholders [current], [found], [percentage]

                * =====================================================

                *

                */

                 

                 

                // example:

                // webviewer.records ( "Record [current] of [found] | [percentage]" ; "#bar { background-color: green }" )

                 

                 

                Let ( [

                  var.record     = Get(RecordNumber);

                  var.found      = Get(FoundCount);

                  var.total      = Get(TotalRecordCount);

                  var.fullset      = Get(TotalRecordCount);

                  isSubset       = var.total = var.found;

                  var.percentage = Truncate ( ( var.record / var.found ) * 100 ; 0 ) & "%";

                  cssBar         = Substitute ( "#bar { background-color: @color; height: 100%; width: @width; }";

                                                [ "@color" ; If ( IsEmpty ( color ) ; "transparent" ; color ) ];

                                                [ "@width" ; var.percentage ]

                                    )

                  ];

                  webviewer.data( "";

                    "<title>Record Information</title>";

                    html.css( "body { text-align: center; margin: 0; border: 0; } #text{ margin:0 auto; }" & cssBar & css ); // load user css after the bar for override support

                    List (

                      "<div id=\"bar\" style=\"position: absolute; top: 0; left: 0;\"></div>";

                      "<div id=\"text\" style=\"position: absolute; top: 0; left: 0; width: 100%\">";

                      Substitute (

                        format;

                        [ "[current]" ; var.record ];

                        [ "[found]" ; var.found ];

                        [ "[percentage]" ; var.percentage ]

                      );

                      "</div>";

                    )

                  )

                )

                • 5. Re: Webviewer field to show counters
                  timwhisenant

                  Hi Peter,

                   

                  Almost but no banana.

                   

                  /*

                  * =====================================================

                  * webviewer.records ( format ; css ; color )

                  *

                  * RETURNS: (string) Web viewer using formatted string

                  * DEPENDENCIES: webviewer.data(), html.document(), html.css()

                  * NOTES: Available placeholders [current], [found], [fullset] [percentage]

                  * =====================================================

                  *

                  */

                   

                  // example:

                  // webviewer.records ( "Record [current] of [found]  Total [fullset]| [percentage]" ; "#bar { background-color: green }" )

                   

                  Let ( [

                    var.record = Get(RecordNumber);

                    var.found = Get(FoundCount);

                    var.total = Get(TotalRecordCount);

                    isSubset = var.total = var.found;

                    var.percentage = Truncate ( ( var.record / var.found ) * 100 ; 0 ) & "%";

                    cssBar = Substitute ( "#bar { background-color: @color; height: 100%; width: @width; }";

                                                  [ "@color" ; If ( isempty ( color ) ; "transparent" ; color ) ];

                                                  [ "@width" ; var.percentage ]

                                      )

                    ];

                    webviewer.data( "";

                      "<title>Record Information</title>";

                      html.css( "body { text-align: center; margin: 0; border: 0; } #text{ margin:0 auto; }" & cssBar & css ); // load user css after the bar for override support

                      List (

                        "<div id=\"bar\" style=\"position: absolute; top: 0; left: 0;\"></div>";

                        "<div id=\"text\" style=\"position: absolute; top: 0; left: 0; width: 100%\">";

                        Substitute (

                          format;

                          [ "[current]" ; var.record ];

                          [ "[found]" ; var.found ];

                          [ "[fullset]"; var.total];

                          [ "[percentage]" ; var.percentage ]

                        );

                        "</div>";

                      )

                    )

                  )

                   

                  Notice the substitute statement at the end. this is no doubt what is lacking.

                   

                  Hope this Helps,

                  Tim

                   

                  p.s. Your var.fullset is not needed, just use the var.total already defined.

                  • 6. Re: Webviewer field to show counters
                    psijmons

                    Thanks Tim,
                    I thought the 2nd part was for rendering the record position, not the text. But this works fine now.

                    Peter

                    • 7. Re: Webviewer field to show counters
                      timwhisenant

                      Peter,

                       

                      You are welcome. Glad I could help.

                       

                       

                       

                      Tim