I am creating a system that manages event expenses.
In this system, one event can have multiple installments of a single payment. What I am trying to do is to show these installments whenever the user hovers its mouse over an event in the Table. (Each row represents one event)
These installments can vary from one to multiple, meaning all events won't have same number of installments.
So, what I did was basically this,
So, if you can see, basically green buttons represent paid installments and yellow warning buttons represent unpaid installments.
but problem is, they are being shown under a single column. I want these to be spread horizontally under that row, rather than being shown under a single column.
Here's a code that I am using to show this datatable, (only including the relevant code)
<style type="text/css">
#events-table tr .links
{
display:none;
}
#events-table tr:hover .links
{
display:block;
}
</style>
<!-- Begin Page Content -->
<div class="container-fluid">
<!-- Page Heading -->
<h1 class="h3 mb-4 text-gray-800">Events</h1>
<div class = "container mb-3 mt-3" id = "events_table">
</div>
jQuery code
$(document).ready(function(){
function getEvents() {
$.ajax ({
url: "action.php",
type: "POST",
data: {action: "get_events"},
success: function(response) {
$("#events_table").html(response);
table = $("table").DataTable({
pagingType: 'full_numbers',
filter: true,
});
}
})
}
getEvents();
});
And this is the action.php file, this is where I am writing all the syntax for this table.
if (isset($_POST['action']) && $_POST['action'] == "get_events")
{
$output = '';
$data = $db->get_all_events();
$output .= '
<table id = "events-table" class = "table table-striped table-bordered ">
<thead>
<tr>
<th data-field="id" data-sortable = "true">ID</th>
<th data-field="event_name" data-sortable = "true">Event Name</th>
<th data-field="date" data-sortable = "true">Date</th>
<th data-field="payment" data-sortable = "true">Total Payment</th>
<th data-field="expense" data-sortable = "true">Expenses</th>
<th data-field="profit" data-sortable = "true">Profit</th>
<th data-field="actions" data-sortable = "false">Actions</th>
</tr>
</thead>
<tbody>';
$number = 1;
foreach($data as $row)
{
$expense = $row['discount']+$row['photo']+$row['video'];
$profit = $row['payment'] - $expense;
$date = $row['day'].'-'.$row['month'].'-'.$row['year'];
$output .= '<tr class ="text-center text-secondary">
<td>'.$number.'</td>
<td>'.$row['e_name'].'';
$payments = $db->get_payments($row['c_id']);
foreach ($payments as $payment)
{
if ($payment['p_status'] == 'pending')
{
$output .= '<div class="links" style = "margin-right: 50%; margin-top: 10px;">
<a id="do_payment" data-id1= '.$payment['p_id'].' class="btn btn-warning btn-icon-split"> <span class="icon text-white-50"> <i class="fas fa-exclamation-triangle"></i> </span> <span class="text">'.$payment['p_amount'].'</span></div>';
}
else
{
$output .= '<div class="links" style = "margin-right: 50%; margin-top: 10px;">
<a id="remove_payment" data-id1= '.$payment['p_id'].' class="btn btn-success btn-icon-split"> <span class="icon text-white-50"> <i class="fas fa-check"></i> </span> <span class="text">'.$payment['p_amount'].'</span></div>';
}
}
$output .='</td>
<td>'.$date.'</td>
<td>'.$row['payment'].'</td>
<td style="color: red">'.$expense.'</td>
<td style="color: green">'.$profit.'</td>
<td><a id="view_event" data-id1 = '.$row['c_id'].' class="btn btn-outline-info btn-sm" href="">View</a>
<a id="update_event" data-id1 = '.$row['c_id'].' class="btn btn-outline-secondary btn-sm" href="">Update</a>
<a id="delete_event" data-id1 = '.$row['c_id'].' class="btn btn-outline-danger btn-sm" href="">Delete</a></td>
</tr>';
$number++;
}
$output .= '</tbody></table>';
echo $output;
}
As you would notice, currently I have my buttons set under the "Event Name" field. I would like to have those buttons spread over the whole row. Any help would be really appreciated.
Also, can anyone tell how can I align the Show entries and the Search Bar on top of the table? Thank you.
Edit: I tried to use the colspan property by creating a new row in the table and put my buttons in it (as suggested in comments) but it did not work out for me. Instead, it showed some very undesirable results.
First of all, the buttons did separate from the "one" column, so that issue did get resolved but in this case, now all the similar buttons were in same column still. For example, Green buttons were stacked up upon each other while yellow buttons were separate but stacked up upon each other.
Plus, bigger problem was now the buttons would show only when I "hover" over the row under the "Events" Row. It has a created a very small White Line under each row to represent the buttons row and Buttons get displayed only when I hover over that white line while nothing shows up when I hover over the actual Event Row.
The new modified code of action.php is as follows,
if (isset($_POST['action']) && $_POST['action'] == "get_events")
{
$output = '';
$data = $db->get_all_events();
$output .= '
<table id = "events-table" class = "table table-striped table-bordered ">
<thead>
<tr>
<th data-field="id" data-sortable = "true">ID</th>
<th data-field="event_name" data-sortable = "true">Event Name</th>
<th data-field="date" data-sortable = "true">Date</th>
<th data-field="payment" data-sortable = "true">Total Payment</th>
<th data-field="expense" data-sortable = "true">Expenses</th>
<th data-field="profit" data-sortable = "true">Profit</th>
<th data-field="actions" data-sortable = "false">Actions</th>
</tr>
</thead>
<tbody>';
$number = 1;
foreach($data as $row)
{
$expense = $row['discount']+$row['photo']+$row['video'];
$profit = $row['payment'] - $expense;
$date = $row['day'].'-'.$row['month'].'-'.$row['year'];
$output .= '<tr class ="text-center text-secondary">
<td>'.$number.'</td>
<td>'.$row['e_name'].'';
$output .='</td>
<td>'.$date.'</td>
<td>'.$row['payment'].'</td>
<td style="color: red">Rs. '.$expense.'</td>
<td style="color: green">Rs. '.$profit.'</td>
<td><a id="view_event" data-id1 = '.$row['c_id'].' class="btn btn-outline-info btn-sm" href="">View</a>
<a id="update_event" data-id1 = '.$row['c_id'].' class="btn btn-outline-secondary btn-sm" href="">Update</a>
<a id="delete_event" data-id1 = '.$row['c_id'].' class="btn btn-outline-danger btn-sm" href="">Delete</a></td>
</tr>
<tr><td colspan="5">';
$payments = $db->get_payments($row['c_id']);
$output .= '<div class="links">';
foreach ($payments as $payment)
{
if ($payment['p_status'] == 'pending')
{
$output .='<a id="do_payment" data-id1= '.$payment['p_id'].' class="btn btn-warning btn-icon-split"> <span class="icon text-white-50"> <i class="fas fa-exclamation-triangle"></i> </span> <span class="text">'.$payment['p_amount'].'</span></div>';
}
else
{
$output .='<a id="remove_payment" data-id1= '.$payment['p_id'].' class="btn btn-success btn-icon-split"> <span class="icon text-white-50"> <i class="fas fa-check"></i> </span> <span class="text">'.$payment['p_amount'].'</span></div>';
}
}
$output .='</td></tr>';
$number++;
}
$output .= '</tbody></table>';
echo $output;
}

