skip to Main Content

I just updated this data table to display another column but now the the ERP Color is displaying in the wrong column, as seen below the color should be under the column ERP not Recipe

ERP Color

Below is how my data table is set up:

var largePressTable;
var largeMC;

var startedLarge = false;
   
function getLargeDryMixTable(start, finish) {

    date_range = "Start:&nbsp&nbsp&nbsp<span class="selectedDate">" + start + "</span> 7am<br />Finish: <span class="selectedDate">" + finish + "</span> 7am";
    document.getElementById('PressTableLargeTitle').innerHTML = date_range;

    largePressTable = $('#largeTableWidthPressID').DataTable( {
         destroy: true,
         ajax: {
           'type': 'POST',
           'url': '../ajax/drymix/drymixTable.ajax.php',
           'data': {
              'getDrymixData': start,
              'endDate': finish,
            }
         },
         dom:
           "<'row'<'col-6 col-md-4 col-lg-3'l><'col-md-4 col-lg-6 d-none d-md-block text-center'B><'col-6 col-md-4 col-lg-3'f>>" +
           "<'row'<'col-sm-12'tr>>" +
           "<'row'<'col-sm-5'i><'col-sm-7'p>>",
         buttons: ['csv', 'print'],
         columns: [
             { "data": "sdate" },
             { "data": "stime" },
             { "data": "etime" },
             { "data": "cycletime" },
             { "data": "shift" },
             { "data": "item" },
             { "data": "erp" }
         ],
         fixedHeader: {
                   headerOffset: 65
         },
         order: [[ 0, "desc" ], [ 1, "desc" ]],
         createdRow: function( row, data, dataIndex){
                         if( data['erp_color'] == 1){
                           $(row).addClass('goodERP');
                         } else {
                           $(row).addClass('badERP');
                         }
                       }
     } );

     if ($(window).width() >= 992) {
       if (startedLarge){
         largeMC.destroy();
       }
       startedLarge = true;

       var largeTable = document.getElementById("medTableWidthPressID");
       largeMC = new Hammer(largeTable, { inputClass: Hammer.TouchInput });


       largeMC.on("swiperight", function() {
         largePressTable.page( 'previous' ).draw( 'page' );
       });

       largeMC.on("swipeleft", function() {
         largePressTable.page( 'next' ).draw( 'page' );
       });
     }

}

Also here is my back end as well:

function create_drymix_table_data($dbquery){
    global $db;
    $data = [];
    $k = 0;

    // sequence_no,sample_datetime,start_end,item,shift,erp_update,wip_entity_name
    while ($a_row = $dbquery->fetch_assoc()) {
        $i = 0;
        $start = $a_row['sequence_no'] - 1;
        $end = $a_row['sequence_no'];
        $cycle_endtime = "Not Complete!";
        $num_rows = $dbquery->num_rows;
        if ($i == 0 && $a_row['start_end'] == 1){
            $number = $a_row['sequence_no'] + 1;
            $this_query_string = "SELECT sample_datetime 
                                    FROM dry_mix 
                                    WHERE sequence_no = $number 
                                    AND note IS NULL";
            $quick_dbquery = basicQuery($this_query_string, $db);
            $count = $quick_dbquery->num_rows;
            if ($count > 0){
                while ($this_row = $quick_dbquery->fetch_assoc()){
                    $cycle_endtime = $this_row['sample_datetime'];
                    $cycle_etime = explode(" ", $cycle_endtime);
                }
            } else {
                $cycle_etime = "-";
            }
        }

        if ($a_row['start_end'] == 1){
            $cycle_starttime = $a_row['sample_datetime'];
            $cycle_stime = explode(" ", $cycle_starttime);
            if ($a_row['erp_update'] == 'Y') {
                $erp_color = 1;
            } else {
                $erp_color = 0;
            } 
            if(isset($cycle_starttime)){
                $cycletime = timeduration($cycle_starttime, $cycle_endtime);
            } else {
                $cycletime = "";
            }
            if ($k == $num_rows){
                $html_item = "<a class="default-link" onclick="getDetails('" . $start . "', '" . $end . "')">" . $a_row['item'] . "</a>";
                $data[] = array("sdate" => $cycle_stime[0], 
                                "stime" => $cycle_stime[1],
                                "etime" => $cycle_etime[1], 
                                "cycletime" => $cycletime, 
                                "shift" => $a_row['shift'], 
                                "item" => $html_item, 
                                "erp" => $a_row['wip_entity_name'], 
                                "erp_color" => $erp_color);
            }
        } elseif ($a_row['start_end'] == 0 && $k > 0){
            $html_item = "<a class="default-link" onclick="getDetails('" . $start . "', '" . $end . "')">" . $a_row['item'] . "</a>";
            $data[] = array("sdate" => $cycle_stime[0], 
                            "stime" => $cycle_stime[1],
                            "etime" => $cycle_etime[1], 
                            "cycletime" => $cycletime, 
                            "shift" => $a_row['shift'], 
                            "item" => $html_item, 
                            "erp" => $a_row['wip_entity_name'], 
                            "erp_color" => $erp_color);
        }

        $i++;
        $k++;
    }
    return $data;
}

I didn’t write this code, so I don’t know exactly how it is set up to fix this. Can someone point me in the right direction to fix this?

2

Answers


  1. You are not using the correct selector. If you want only one column to be colored try using this selector :

    if(data['erp_color'] == 1) {
       // with eq(1) select the column in position 1
       $('td', row).eq(1).addClass('goodERP')
    } else {
       $('td', row).eq(1).addClass('badERP')
    }
    

    Hope it helps

    Login or Signup to reply.
  2. Please could you try by debugging this part of the code? The following code is responsible for printing or adding a class of colors

    createdRow: function( row, data, dataIndex){
          // use this console to show what happens here
           console.log('erp_color:', data['erp_color']);
    
                         if( data['erp_color'] == 1){
                           $(row).addClass('goodERP');
                         } else {
                           $(row).addClass('badERP');
                         }
                       }
     } );
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search