I am creating a billing application and I am using codeigniter. I have a view where I can view the employee details.In this view file I have a action like delete and edit separately for each employee record. Is is possible to have a single edit button that can edit any employee record that is listed in my view?
My view file
<table class="resizable" bordercolor="#993300" border="1">
<thead>
<tr>
<th class="header">Employee id</th>
<th class="yellow header headerSortDown">First name</th>
<th class="green header">Last name</th>
<th class="red header">Email</th>
<th class="red header">Emergency contact</th>
<th class="red header">Category</th>
<th class="red header">ID card</th>
<th class="red header">Time in</th>
<th class="red header">Time out</th>
<th class="red header">Date of hire</th>
<th class="red header">Date of termination</th>
<th class="red header">Date of rehire</th>
<th class="red header">Reference number</th>
<th class="red header">Service limitation</th>
<th class="red header">Chair renter</th>
<th class="red header">Actions</th>
</tr>
</thead>
<tbody>
<?php
foreach($employee as $row)
{
echo '<tr>';
echo '<td>'.$row['id'].'</td>';
echo '<td>'.$row['emp_first_name'].'</td>';
echo '<td>'.$row['emp_last_name'].'</td>';
echo '<td>'.$row['emp_email_id'].'</td>';
echo '<td>'.$row['emp_emergency_contact'].'</td>';
echo '<td>'.$row['category'].'</td>';
echo '<td>'.$row['emp_id_card'].'</td>';
echo '<td>'.$row['emp_time_in'].'</td>';
echo '<td>'.$row['emp_time_out'].'</td>';
echo '<td>'.$row['emp_date_of_hire'].'</td>';
echo '<td>'.$row['emp_date_of_termination'].'</td>';
echo '<td>'.$row['emp_date_of_rehire'].'</td>';
echo '<td>'.$row['emp_reference_num'].'</td>';
echo '<td>'.$row['emp_service_limitation'].'</td>';
echo '<td>'.$row['chair_renter'].'</td>';
echo '<td class="crud-actions">
view & edit
delete
</td>';
echo '</tr>';
}
?>
</tbody>
</table>
Here i have a <a> to perform edit and delete option. This action passes the id that i choose to edit or delete. Instead of having separate buttons for each employee.I need to have a single button and allow the user to select employee.Like this image
The easiest solution would be to use JQuery to attach a selected class to the row which is clicked via something like:
$('tr').on('click', function () {
// Remove selection from other rows
$('tr.selected').removeClass('selected');
// Add selection to current row
$(this).addClass('selected');
});
That will allow you to place a 'cursor' onto a row, you'll want to style the rows with the selected class using CSS or something similar.
Now you can have a single Edit button and use something like the following code to handle the click event:
$('#edit').on('click', function () {
if ($('tr.selected').length() == 0) {
alert('Must select a row!');
} else {
// Handle 'edit' event by passing $(this) to whatever you need
// $(this) will be the currently selected row
}
});
This works since the $(this) object acts as a reference to the currently selected row.
Related
I am trying to hide the table row for user_id. I only want to show the full name, user name, and actions in the table. I tried to remove the code for the user id row, but it affected the other functionalities like the edit and delete.
here is the code:
<form method="post" id="editForm">
<table class="table">
<tbody>
<tr>
<th scope="col">USER ID</th>
<th scope="col">FULL NAME</th>
<th scope="col">USER NAME</th>
<th scope="col">ACTIONS</th>
</tr>
<?php $a = 0?>
<?php while ($row = mysqli_fetch_array($res)) {
echo "<tr id=".$a++.">
<th scope='row' class='row-data'>".$row['user_id']."</th>
<td class='row-data'>".$row['full_name']."</td>
<td class='row-data'>".$row['user_name']."</td>
<td><input type='button'
value='EDIT'
onclick='editUser()'' /></td>
<td><input type='button'
value='DELETE'
onclick='deleteUser()' /></td>
</tr>
</tbody>";
}; ?>
You could try modifying the editUser() and deleteUser() Javascript methods to accept a userId parameter. It would probably clean up some of the code as well on the JS side. Just a suggestion though. That snippet then might look something like this:
<form method="post" id="editForm">
<table class="table">
<tbody>
<tr>
<th scope="col">FULL NAME</th>
<th scope="col">USER NAME</th>
<th scope="col">ACTIONS</th>
</tr>
<?php $a = 0?>
<?php while ($row = mysqli_fetch_array($res)) {
echo "<tr id='".$a++."'>
<td class='row-data'>".$row['full_name']."</td>
<td class='row-data'>".$row['user_name']."</td>
<td><input type='button'
value='EDIT'
onclick='editUser(".$row['user_id'].")'' /></td>
<td><input type='button'
value='DELETE'
onclick='deleteUser(".$row['user_id'].")' /></td>
</tr>
</tbody>";
}; ?>
Otherwise you could use Ken's solution which would probably work with your existing code.
Instead of removing the column, you can set the display style to 'none' for this column
(add style="display:none;")
Hence (1) change
<th scope="col">USER ID</th>
to
<th scope="col" style="display:none;">USER ID</th>
and (2) change
<th scope='row' class='row-data'>".$row['user_id']."</th>
to
<th scope='row' class='row-data' style="display:none;">".$row['user_id']."</th>
I tried to sort/order data on database. I used this command:
SELECT * FROM `estates`
ORDER BY `estates`.`price` ASC
It take effect on database order. But on webpage it doesn't. How can I make it take effect on webpage too? Any idea? Thank you.
By the way I am using Laravel,
and retriving data from database with MVC
If you need to check to my page structure here it is:
<table cellspacing='0'> <!-- cellspacing='0' is important, must stay -->
<thead>
<tr>
<th width="150px">会社名</th>
<th width="150px">物件名</th>
<th width="250px">住所</th>
<th width="150px">販売価格</th>
<th width="100px">総戸数</th>
<th width="150px">専有面積</th>
<th width="100px">間取り</th>
<th width="100px">バルコニー面積</th>
<th width="100px">竣工時期</th>
<th width="100px">入居時期</th>
</tr>
<thead>
<tbody>
#foreach($estates as $estate)
<tr class="even">
<td>{{$estate->company_name}}</td>
<td>{{$estate->name}}<br/></td>
<td>{{$estate->address}}</td>
<td>{{$estate->price}}</td>
<td>{{$estate->hows_old}}</td>
<td>{{$estate->extend}}</td>
<td>{{$estate->rooms}}</td>
<td>{{$estate->balcon_m2}}</td>
<td>{{$estate->old}}</td>
<td>{{$estate->entery}}</td>
</tr>
#endforeach
</tbody>
</table>
And here is the controller:
public function sumos()
{
$estates = Estates::get();
//test
$data['estates'] = $estates;
return view('welcome', $data);
}
try to use orderBy
Estates::orderBy('price')->get();
i have a question where i want to hide the column in datatable but still need to access its value.
this is my code
<div class="container">
<div class="">
<h1>HRphn</h1>
<div class="col-sm-8">
<div class="well clearfix">
<div class="pull-right"><button type="button" class="btn btn-xs btn-primary" id="command-add" data-row-id="0">
<span class="glyphicon glyphicon-plus"></span> Record</button></div></div>
<table id="posting_grid" class="table table-condensed table-hover table-striped" width="60%" cellspacing="0" data-toggle="bootgrid">
<thead>
<tr>
<th data-column-id="id" data-type="numeric" data-identifier="true">Posting No</th>
<th data-column-id="position">Position</th>
<th data-column-id="department">Department</th>
<th data-column-id="vacancy">Vacancy</th>
<th data-column-id="postingdate">Date</th>
<th data-column-id="status">Status</th>
<th data-column-id="qualification" clas="hidden-lg"></th>
<th data-column-id="experience" class="hidden-lg"></th>
<th data-column-id="criteria1" class="hidden-lg"></th>
<th data-column-id="criteria2" class="hidden-lg"></th>
<th data-column-id="criteria3" class="hidden-lg"></th>
<th data-column-id="jd1" ></th>
<th data-column-id="jd2" ></th>
<th data-column-id="jd3" ></th>
<th data-column-id="jd4" ></th>
<th data-column-id="jd5" ></th>
<th data-column-id="commands" data-formatter="commands" data-sortable="false">Commands</th>
</tr>
</thead>
</table>
</div>
i want to hide this
<th data-column-id="qualification" data-class="hidden"></th>
<th data-column-id="experience" data-class="hidden"></th>
<th data-column-id="criteria1" data-class="hidden"></th>
<th data-column-id="criteria2" data-class='hidden'></th>
<th data-column-id="criteria3" data-class='hidden'></th>
<th data-column-id="jd1" ></th>
<th data-column-id="jd2" ></th>
<th data-column-id="jd3" ></th>
<th data-column-id="jd4" ></th>
<th data-column-id="jd5" ></th>
but..if i hide those value..i cant access them at
grid.find(".command-edit").on("click", function(e)
{
//alert("You pressed edit on row: " + $(this).data("row-id"));
var ele =$(this).parent();
var g_id = $(this).parent().siblings(':first').html();
var g_name = $(this).parent().siblings(':nth-of-type(7)').html();
console.log(g_id);
console.log(g_name);
//console.log(grid.data());//
$('#edit_model').modal('show');
if($(this).data("row-id") >0) {
// collect the data
// $('#edit_id').val(ele.siblings(':first').html()); // in case we're changing the key
$('#edit_position').val(ele.siblings(':nth-of-type(2)').html());
$('#edit_department').val(ele.siblings(':nth-of-type(3)').html());
$('#edit_vacancy').val(ele.siblings(':nth-of-type(4)').html());
$('#edit_qualification').val(ele.siblings(':nth-of-type(7)').html());
$('#edit_experience').val(ele.siblings(':nth-of-type(8)').html());
$('#edit_postingdate').val(ele.siblings(':nth-of-type(5)').html());
$('#edit_status').val(ele.siblings(':nth-of-type(6)').html());
// $('#edit_description').val(ele.siblings(':nth-of-type(9)').html());
} else {
alert('Now row selected! First select row, then click edit button');
}
})
i have tried solution at Bootstrap-Table: How to hide a column without deleting it from the DOM?
but it doesnt seem to hide the column at all
If you are using bootstrap 4+ just add the class .d-none to your columns,
which will set display: none on them.
If you are using bootstrap 3+ it should be .hidden-* where as * is
xs
sm
md
lg
for the different screen sizes.
Maybe .hidden works as well without the size selector...
Facing issue to get multiple checkbox array values in Codeignite
<div class="form-actions">
<form action="candidates/posted" name="posted" method="post">
<button class="btn btn-primary" type="submit" value="submit" name="submit">Action</button>
</div>
<table class="table table-striped table-bordered table-condensed">
<thead>
<tr>
<th class="header">#</th>
<th class="checkbox">Status</th>
<th class="yellow header headerSortDown">Roll No</th>
<th class="green header">Class Name</th>
<th class="red header">Full Name</th>
<th class="red header">Father Name</th>
<th class="red header">Sections</th>
<th class="red header">Actions</th>
</tr>
</thead>
<tbody>
<?php
foreach($candidates as $row)
{
echo '<tr>';
echo '<td>'.$row['id'].'</td>';
//echo '<td>' .'</td>';
echo '<td><input type="checkbox" class ="chkCheckBoxId" value='.$row['id'].' name="chk_id[]"/></td>';
echo '<td>'.$row['roll_no'].'</td>';
echo '<td>'.$row['class_name'].'</td>';
echo '<td>'.$row['full_name'].'</td>';
echo '<td>'.$row['father_name'].'</td>';
echo '<td>'.$row['section_name'].'</td>';
echo '<td class="crud-actions">
view & edit
delete
</td>';
echo '</tr>';
}
?>
</form>
Controller here:
public function posted()
{
if(!empty($_POST['chk_id'])) {
foreach($_POST['chk_id'] as $check) {
echo $check;
}
}
}
Just try like this inside foreach loop.There is conflict on using quotes.
$id = $row['id'];
echo '<td><input type="checkbox" class ="chkCheckBoxId" value="'.$id.'" name="chk_id[]"/></td>';
In codeigniter you can use $this->input->post() to get posted values.So following is a better way..
public function posted()
{
if(!empty($this->input->post('chk_id')) {
foreach($this->input->post('chk_id') as $check) {
echo $check;
}
}
}
Correct me on this but I believe that an unchecked checkbox does not get sent back to the server. I have always checked to see if a checkbox is checked by seeing if it is in the $_POST[] array (I tend to use method="post").
When I need an array of checkboxes, I actually give them their own names. If I am listing a group of products for users to choose, for example, I will give each checkbox a name that starts with "chk_" and then append the ID of the product. This way, during processing the data, all I have to do is loop through the $POST[] array and every object that starts with chk is a checkbox and the rest indicates which product they chose.
I am using bootstrap at http://communitychessclub.com/games.php -it's a table that displays records of chess games. I want a row to be clickable like:
<?php
echo "<tr onclick=\"location.href='basic.php?game=$game'\" >";
?>
The trouble is that the code to load and display the json table data doesn't include "TR" for displaying data; it's simply this:
<table data-toggle="table" data-url="games.json" data-cache="false"
data-search="true" data-show-refresh="true" data-show-toggle="true"
data-show-columns="true">
<thead>
<tr>
<th data-field="game" class="hidden-xs hidden-sm hidden-md
hidden-lg">#</th>
<th data-field="Date">Date</th>
<th data-field="ECO">ECO</th>
<th data-field="Event">Event</th>
<th data-field="WhiteElo">Rat.</th>
<th data-field="White">White</th>
<th data-field="BlackElo" >Rat.</th>
<th data-field="Black">Black</th>
</tr>
</thead>
</table>
I want to grab the game number (data-field="game") and
<?php
echo "<tr onclick=\"location.href='basic.php?game=$game'\" >";
?>
How could I proceed?