Why buttons not showing in the table?

Why buttons not showing in the table?

DevMushrefDevMushref Posts: 10Questions: 4Answers: 0

I can't find the issue, since the debugger is not actually showing my any errors...

Here is my code:

var dataTable = $('#violation_data').DataTable({
      "searching": true,
      "processing": true,
      "serverSide": true,
      "order": [],
      "ajax": {
         url: "/traffic-fetch",
         type: "POST",
      },
      dom: 'Bfrtip',
      buttons: [
         'copy', 'excel', 'pdf'
     ],
      "columnDefs": [
         {
            "target": [0, 3, 4],
            "orderable": true
         }
      ]
   });

I followed what I understood from the docs regarding buttons but still.. Not sure why they aren't showing. I am also using server-side:

$query = "SELECT * FROM traffic_violations";
$query .= " WHERE ";

if(isset($_POST["search"]["value"]))
{
 $query .= '(plateNumber LIKE "%'.$_POST["search"]["value"].'%"';
 $query .= 'OR carModel LIKE "%'.$_POST["search"]["value"].'%"';
 $query .= 'OR carColor LIKE "%'.$_POST["search"]["value"].'%" ';
 $query .= 'OR violationType LIKE "%'.$_POST["search"]["value"].'%" ';
 $query .= 'OR violationLocation LIKE "%'.$_POST["search"]["value"].'%" ';
 $query .= 'OR ownerGender LIKE "%'.$_POST["search"]["value"].'%" ';
 $query .= 'OR violationDateTime LIKE "%'.$_POST["search"]["value"].'%" ';
 $query .= 'OR cccEmployee LIKE "%'.$_POST["search"]["value"].'%")';
}
if(isset($_POST["order"]))
{
 $query .= 'ORDER BY '.$_POST["order"]["0"]["column"].' '.$_POST["order"]["0"]["dir"].' ';
}
else
{
 $query .= 'ORDER BY id DESC ';
}
if($_POST["length"] != -1)
{
 $query .= 'LIMIT ' . $_POST['start'] . ', ' . $_POST['length'];
}

$statement = $connection->prepare($query);
$statement->execute();

$result = $statement->fetchAll();
$data = [];

$filtered_rows = $statement->rowCount();

foreach ($result as $row) {
    $traffic_doc = "";
    if ($row["violationStatement"] != "") {
        $traffic_doc =
            '<img src="./uploads/' .
            $row["violationStatement"] .
            '" class="img-thumbnail" width="50" height="35" />';
    } else {
        $traffic_doc = "";
    }

    $sub_array = [];

    $sub_array[] = $row["plateNumber"];
    $sub_array[] = $row["carModel"];
    $sub_array[] = $row["carColor"];
    $sub_array[] = $row["violationType"];
    $sub_array[] = $row["violationLocation"];
    $sub_array[] = $row["violationDateTime"];
    $sub_array[] = $traffic_doc;
    $sub_array[] = $row["cccEmployee"];
    // $sub_array[] = $row["ownerGender"];
    // $sub_array[] = $row["workingShift"];
    // $sub_array[] = $row["violationAction"];
    $sub_array[] = '<a href="javascript:void(0)" name="update" class="update" id="' . $row["id"] .'">
                         <i class="fas fa-edit"></i>
                    </a>';
    $sub_array[] = '<a href="javascript:void(0)" name="delete" class="delete" id="' . $row["id"] .'">
                         <i class="fas fa-trash-alt"></i>
                    </a>';

    $data[] = $sub_array;
}

$output = [
    "draw" => intval($_POST["draw"]),
    "recordsTotal" => $filtered_rows,
    "recordsFiltered" => get_total_violations(),
    "data" => $data,
];

echo json_encode($output);

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    The table initialisation looks fine. Have you included the relevant source files - the download builder will ensure you have the right files in the right order.

    If that doesn't help, we're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • DevMushrefDevMushref Posts: 10Questions: 4Answers: 0

    Dear Colin, thank you for your reply.

    Yes it turned out I was using old versions of the library. However, all the buttons work except Excel..

  • DevMushrefDevMushref Posts: 10Questions: 4Answers: 0

    And I published the site on a temporary domain here:
    http://abdulrahmanm8.sg-host.com

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    I'm not seeing a table on that page, cam you tell me where to go, please,

    Colin

Sign In or Register to comment.