You are viewing limited content. For full access, please sign in.

Question

Question

Scroll right to left on a table

asked on February 8, 2023

I have a table with a lot of headers in a form.  This form is only used to display data and not saved anywhere.  Is there a way to have the table scroll right to left and keep the column width as specified so the data can be read? I have attached an example.

Table Example.PNG
0 0

Replies

replied on February 8, 2023

This can be done with Javascript on the Classic Designer.  This was tested in Forms version 11.0.2212.30907.

There are a couple items we need to address:

  1. The archived version of the form will end up with much of your table hidden if we do this.  In your case, you've said this form won't be submitted, so that shouldn't be an issue.  But if you do this on a form that can be archived, you need to be able to address that to ensure the form is handled differently, or make an alternate version of the form for archival.
     
  2. The column widths set on the Layout page are percentages, but to have a table that can scroll, we need these to be fixed values.  Unfortunately, there isn't a way to set fixed values on the Layout page, so we need to address this in the Javascript.  Here's how:
     
    • If we want all of the columns to be the same width (let's say 150px), then we can do that fairly easily using Javascript like this (your table will need the scrollingTable class to be assigned to it).  This script loops through all of the column headers and sets their width to 150px, and then modifies the CSS of the table to allow overflow (which is where the scrolling comes in). 
      $(document).ready(function () {  
        $('.scrollingTable thead th').each(function() {   
          $(this).css('width', '150px');
        });
        $('.scrollingTable .cf-table_parent').css('overflow', 'auto');
      });

       
    • If we want different column widths, then we need to do this for each column.  The easiest way to do that is via the "q0" id value for each field, since that exists on the header where we need to set the width (your table will need the scrollingTable class to be assigned to it).  This script loops through each of the column headers and sets their values based on their "q0" id value, or to 100px if their ID wasn't specifically listed (this is good if most of the columns are the same width, and only some need to be wider).  After changing their widths it modifies the CSS of the table to allow overflow (which is where the scrolling comes in).
      $(document).ready(function () {  
        $('.scrollingTable thead th').each(function() {   
          if($(this).attr('id') == 'q1') { $(this).css('width', '150px'); }
          else if($(this).attr('id') == 'q2') { $(this).css('width', '200px'); }
          else if($(this).attr('id') == 'q3') { $(this).css('width', '250px'); }
          else if($(this).attr('id') == 'q4') { $(this).css('width', '300px'); }
          else if($(this).attr('id') == 'q5') { $(this).css('width', '350px'); }
          else if($(this).attr('id') == 'q6') { $(this).css('width', '400px'); }
          else if($(this).attr('id') == 'q7') { $(this).css('width', '500px'); }
          else { $(this).css('width', '100px'); }
        });
        $('.scrollingTable .cf-table_parent').css('overflow', 'auto');
      });

       

0 0
replied on June 13, 2023

Hey,

This is not possible with the new designer ?

0 0
replied on June 13, 2023

No, the Forms Layout Designer runs Javascript within a sandboxed iFrame, so it can only modify the parts of the form components that have been opened up through the LFForm interface, it cannot modify the underlying structure of form components like this.

So I would still with the Classic Designer for anything needing this.  The Layout Designer has some great strengths and will continue to improve, but the Classic Designer still has a place with things like this.

1 0
You are not allowed to follow up in this post.

Sign in to reply to this post.