Loading...

Calling JavaScript from body of qListView custom display

Calling JavaScript from body of qListView custom display

Home Forums QuickApps Forum Calling JavaScript from body of qListView custom display

  • This topic is empty.
Viewing 3 reply threads
  • Author
    Posts
    • #5359
      Anonymous
      Anonymous
      Participant

      Hi Joseph,

         Please take a look at this tread http://communities.quest.com/thread/21015?tstart=0 .

      It explains in great details how to use the js code within qListView and it comes with working code sample.

      Also please check the documentation for more details.

      If you have any questions please let me know.

    • #5360
      Anonymous
      Anonymous
      Participant

      Have you tried something like the following?

      <script>if (<%IntField%> > 10) document.write("<span color=red>" + <%IntField%> + "</span>")</script>

      However I would recommend NOT using Custom Display tab in this case. We should have example of using Content Editor Web Part or Html Form Web Part to sneak in some Javascript function that you can use with Display Field -> Custom Field -> Calculated Format attribute to render the field with some simple logic.

      Basically you put the following script in the OOTB HTML Form Web Part (by using the Source Editor and replace the whole default text).

      <script language="text/javascript">

      function FormatNumber(num) {   

        if (num.Length == 0) return ' ';   

          

        var iNum = parseFloat(num);

        if (iNum < 0.5) {

             return '<font color="red">' + num + '</font>';   

        } else {

             return '<font color="green">' + num + '</font>';   

        }

      }

      </script>

      Then you add a Custom Field to your list view, and specify Calculated Format as following:

      <script>FormatNumber('<%YourColumnName%>');</script>

      And you should be done.

    • #4257
      Anonymous
      Anonymous
      Participant

      I’ve set up my qListView web part to not show the grid and only show the data formatted by using the Custom Display tab. 

      It’s simple enough to create some JavaScript functions between some <script> tags and throw them up in the header section, but what I need to know is how to call those functions from inside the body section, such that the data coming from the list in the  <%fieldname%> tags is used as parameters to the functions.  I’d like to be able to run the JavaScript against the values returned by each list item that is returned for display.  For example, if I’m returning a date field, I’d like to color code the date value red if it is than one week away from the current date.

      I think this is fairly easy to do if I was using the grid — there’s a way to substitute a processed value for a selected field.  But how to actually call the JavaScript on each item that is returned in the custom display is proving to be a challenge.  Any suggestions will be appreciated.

    • #5836
      Anonymous
      Anonymous
      Participant

      >>I would recommend NOT using Custom Display tab<<

      I agree that would not be the best place for the JS;  using an HTML Form or Content Editor web part would be better (and an external JS file included in the page by a reference in my custom master page would be even better).

      As for the rest, placing <script> tags in the body section with "immediate" execution JavaScript code worked just fine, so thanks for that.

      Sure wish there was an option on this thing to tell it to just return the list values as XML so I could just do the styling with XSLT instead of having to write all this executable code just to format my output.

      Thanks again.

Viewing 3 reply threads

You must be logged in to reply to this topic.