Presenting a 24-column data table fetched from MySQL and integrated into a webpage through JavaScript DataTables

Greetings everyone! I have a query regarding Javascript DataTables and how it displays data from a MySQL table.

Here's the MySQL query in question:

select LOT_LOCATION, `Zone Attribute`, a.LOTID, Design_ID, ifnul(Board_ID,'') as Board_ID1, QA_WORK_REQUEST_NUMBER, QA_PROCESS_TYPE, QA_PROCESS_NAME, CURRENT_QTY, Date, Temperature, Humidity, CONCAT(b.Zone1_Voltage, 'V, ', b.Zone1B_Voltage, 'V, ',b.Zone1C_Voltage, 'V') AS Voltage_1, CONCAT(b.Zone1_Current, 'A, ', b.Zone1B_Current, 'A, ',b.Zone1C_Current, 'A') AS Current_1, CONCAT(b.Zone2_Voltage, 'V, ', b.Zone2B_Voltage, 'V, ',b.Zone2C_Voltage, 'V') AS Voltage_2, CONCAT(b.Zone2_Current, 'A, ', b.Zone2B_Current, 'A', ......(continued)....... b.Zone6_Voltage, 'V, ',b.Zone6C_Voltage, 'V') AS Voltage_6, CONCAT(b.Zone6_Current, 'A, ', b.Zone6B_Current, 'A, ',b.Zone6C_Current, 'A') AS Current_6 from Lab_WIP_History a LEFT join chamber_data b ON a.LOT_LOCATION = b.Testtag  LEFT JOIN chamber_data_1 c ON a.LOTID = c.lotid

And this is the structure of the MySQL table:

LOT_LOCATION, Zone Attribute, LOTID, Design_ID, Board_ID1, QA_WORK_REQUEST_NO, QA_PROCESS_TYPE, QA_PROCESS_NAME, CURRENT_QTY, Date, Temperature, Humidity, Voltage_1, Current_1, Voltage_2, Current_2, Voltage_3, Current_3, Voltage_4, Current_4, Voltage_5, Current_5, Voltage_6, Current_6
'SGHAST.0064', '3', 'CVC66L2.11', 'J39E', '', '106544', 'ROBUSTNESS VALID', 'HAST 110C', '40', '2022-06-13 13:39:42', '109.98', '85.08', '3.6V, 1.95V, V', '0.0A, 0.11A, A', '3.6V, 1.95V, V', '0.0A, 0.1A, A', '3.6V, 1.95V, V', '0.0A, 0.12A, A', '3.6V, 1.95V, V', '0.0A, 0.12A, A', '3.6V, 1.95V, V', '0.0A, 0.12A, A', '3.6V, 1.95V, V', '0.0A, 0.12A, A'

My goal is to display all 24 columns on the same webpage using Javascript DataTables. Below you'll find my JavaScript code:

<script>
  $(document).ready(function() {

    var table = $('#elogbooktable').DataTable( {
      "ajax": {url: "testing_getdetaildata.php", dataSrc: ""},
          'scrollCollapse': false,
          'deferRender':    true,
          'scroller':       true,
          'lengthMenu':     [[50, 75, 100, 200, -1], [50, 75, 100, 200, 'ALL']],
          'iDisplayLength': 50,
          'order': [[ 4, "asc" ]],
          'orderCellsTop' : true,
          'columnDefs': [ {
            'targets': 2,
            'createdCell': function(td, cellData, rowData, row, col) {
              if(rowData[2]) {
                  $(td).html("<a href='http://mamweb.sing.micron.com/MAMWeb/bin/MAMWeb.pl?APP=MAMQASI&ACTION=REPORT&REPORTID=Status&MATYPE=78&FORMAT=HTML&CATEGORIES=ALL&ID="+rowData[2]+"' target='_blank'>"+rowData[2]+"</a>");
              }
            }
          }, {
            'targets': 9,
            'createdCell': function(td, cellData, rowData, row, col) {
              if(rowData[9]) {
                  $(td).text(moment(rowData[9]).format('MM-DD-YYYY hh:mm A'));
              }
            }
          }, {
            'targets': 10,
            'createdCell': function(td, cellData, rowData, row, col) {
              if(rowData[10]) {
                  $(td).text(rowData[10] + " C");
              }
            }
          } ,{
            'targets': 11,
            'createdCell': function(td, cellData, rowData, row, col) {
              if(rowData[11]) {
                  $(td).text(rowData[11] + " %RH");
              }
            }
          }],
          'filterDropDown': {                                       
                        columns: [
                            { 
                                idx: 5
                            }
                        ],
            bootstrap: true
                    },
         rowCallback: function(row, data, index){
            if(new Date(data[42]) < Date.now()){
            $(row).find('td:eq(42)').css('background-color', '#f8d7da');
          }
        },
    });

      <?php $i=13; 
     foreach($columns as $id=>$value) { 
         print "showHideColumn($id, $i);\n";
         $i++;
       } 
      ?>    

    //Add a text search box to each footer cell
    table.columns().every( function () {
      $(this.footer()).html("<input type='text' style='width:100%;' placeholder='Search'/>");
    });
    
    //Full table search functionality
    // Column search function       
    table.columns().every( function () {
      var that = this;
      $( 'input', this.footer() ).on( 'keyup change', function () {
        if ( that.search() !== this.value ) {
          that.search( this.value, true ).draw();
        }
      });
    });
    
    var buttons = new $.fn.dataTable.Buttons(table, {
     'buttons': ['pageLength','copyHtml5',
            {
              extend: 'excelHtml5',
            },
            {
              extend:  'print',
            }]
    }).container().appendTo($('#envdetail_wrapper .col-sm-6:eq(0)'));
    
    setInterval( function () {
      table.ajax.reload();
    }, 300000 );
  
  });



  function showHideColumn(id, number) {
    var dtable = $('#elogbooktable').DataTable();
    
    if(dtable.column(number).visible() === true) {
      if($(id).attr("class").includes("btn-primary")) {
          $(id).removeClass("btn-primary");
          $(id).addClass("btn-default");
        }
        dtable.column(number).visible(false);
    }
    else {
      if($(id).attr("class").includes("btn-default")) {
          $(id).removeClass("btn-default");
          $(id).addClass("btn-primary");
        }
        dtable.column(number).visible(true);
    }
  }

 </script>

However, there seems to be an issue where only the first 13 columns are displayed instead of all 24. Any assistance on solving this would be greatly appreciated. Thank you!

UPDATED:

Here is the HTML code included below:

[HTML CODE GOES HERE]

Answer №1

UPDATE! Modify the following code:

      <?php $i=11;
 foreach($columns as $id=>$value) { 
     print "showHideColumn($id, $i);\n";
     $i++;
   } 
  ?> 

With this one:

  <?php $i=22; 
 foreach($columns as $id=>$value) { 
     print "showHideColumn($id, $i);\n";
     $i++;
   } 
  ?> 

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using hooks for conditional rendering

Background Information : My current project involves creating a form using hooks and rendering components based on the step. Challenge Encountered : I received this error message: "Error: UserFormHooks(...): Nothing was returned from render. This usually ...

"Enhance your web app with Emotion.js and Preact SSR, complete with

In my preact SSR application, I have utilized Emotion JS 10 for styling purposes. My goal was to incorporate RTL support into the app. To achieve this, I implemented createEmotion and createEmotionServer, leveraging the resulting renderStylesToString to r ...

"Relating to meteorjs, admin users are akin to those in

Looking for a package or tutorial to create admin users similar to Django. I want to be able to create superusers through the terminal and have the ability to personalize user schemas with Collection2. Additionally, I would like to remove the option for ...

Upon transitioning between router pages, an error message pops up saying "Vue Socket.io-Extended: this.$socket.$subscribe is not a

I have created a basic Vue application that is designed to connect to a NodeJS server using websockets. My setup involves the use of socket.io-extended for handling the connections. After following the documentation and implementing the websocket connect ...

Looking for a way to efficiently retrieve results by matching multiple string keywords as you go through each line of a file (fs)?

Essentially, I have multiple search strings provided by the client that need to be matched with each line in a file. If a line matches all of the inputted strings, I should add that line to the results array. However, when I run the code below, it only ret ...

"JS Kyle: Utilizing JWT for Signing and Encrypting Data

I am currently using jose for signing and encrypting JWTs, but I am facing an issue when trying to sign and then encrypt the entire JWT. When it comes to signing my JWT, I utilize the following function: const secretKey = process.env.JWT_SECRET; const key ...

Combining and removing identical values in JavaScript

I need to sum the price values for duplicated elements in an array. Here is the current array: var products = [["product_1", 6, "hamburger"],["product_2", 10, "cola"],["product_2", 7, "cola"], ["product1", 4, "hamburger"]] This is what I am aiming for: ...

Ways to identify and differentiate user clicks on various buttons

I have generated 3 different plan options from an array of objects retrieved from the backend. Depending on whether the plan is cheaper, the user's subscription, the corresponding button will display "downgrade", more expensive, the button will show ...

Determine the overall cost based on varying percentage increases for each step

I am currently working on developing a price estimation calculator. Here is the breakdown: For 1000 MTU, the price will be 0.035, resulting in a total of 35. For 2000 MTU, the price will be 0.034, making the total 67. For 3000 MTU, the price will be 0.03 ...

What strategies can be employed to reduce the need for numerous if-else statements in my JavaScript code?

In my input form, users have the ability to make edits. I need to send only the data that has been changed by the user. Currently, I am repeating the same lines of code multiple times to compare and determine what data needs to be sent. Is there a more e ...

Ways to conceal numerous objects

I need to create a function where I can hide multiple elements by pressing a button based on the value of checkboxes. If a checkbox is checked, the corresponding element should be hidden. Currently, I have some code that only works for the first element: ...

Retrieve the key{index} property from the .map method in React for the element that was just clicked

I am facing an issue with my code const Component = () => { const [Clicked, setClicked] = useState(false); const handleClick = (prop, e) => { console.log(prop); } return ( <div> {arrayCard.map((item, i) => { ...

Tone.js is failing to sync sequences during playback

I'm currently working on developing a sequencer using Tone.js. Right now, I have a basic sequence that plays when the user clicks the play button. However, I've encountered an issue where if the button is pressed to pause and then played again, t ...

The jQuery script tag fails to recognize click events once dynamically loaded with the load event

Hey there, I recently utilized this script in a SAP WebDynpro setup to dynamically load and employ jQuery. The onload event of the script tag is functioning well as I can select the text of the focused element. However, I am facing issues with registering ...

Transforming intricate JSON data into a structured table format

I'm struggling to transform the nested JSON data into an HTML table, but I keep encountering an error. I'm uncertain about where I may have made a mistake. Could it be related to how I am trying to access the array within the object? Here' ...

How to dynamically update the maximum y-axis value in Vue-Chart.js without having to completely re-render the entire

Currently, I am involved in a project that requires the implementation of various charts from the Vue-Chartjs library. One specific requirement is to dynamically change the maximum value on the Y-axis whenever users apply different filters. To achieve this ...

What is the proper way to detach an event listener from a class?

I am facing a challenge when trying to remove an event listener. After running the script, I receive an error message stating that changeGirl.off("click") is not a function. Despite this issue, everything else within the code is working perfectly fine. Any ...

Change the size of the font with a slider in VueJS

I have been utilizing the project found at This particular project allows end-users to reuse Vue components as editable sections by providing a styler overlay for adjusting content within a div or section. After installation, I added a slider which now ap ...

Dual Camera Toggle Functionality with Three.js Orbit Controls

I am facing an issue with two cameras in one scene, one viewport, and one renderer. I switch between cameras using HTML buttons. ISSUES Issue 1 When using camera1, there is no response from moving the mouse. However, when I switch to camera2, the orbit ...

How can I retrieve the data returned by an ajax call using jQuery?

I have a function that is making an AJAX call to return data. Here is the code: function reqNodelistByField( i ) { $.ajax({ type: 'post', url: './req.nodelist.by.field.php', dataType: 'text', ...