I posted another question for issue and it was partially solved. I have a table with a single link on each row. The link calls AJAX and outputs in another Bootstrap column. This works fine. When I click the link, the class "highlight" is applied which changes the background color of the row. When I click another link I want the previously clicked clink to have the "highlight" class removed and the new row to have the class applied.
Currently, the add class works but any other link click get the class added but the class is never removed.
<table class="table table-hover unpadded" id="mashed_tab">
<thead>
<tr>
<th class="artcl_hdr text-center" colspan="2">
<p class="big_date top_pad"><i class="fa fa-rss fa-lg concrete"></i> Articles/Keywords for
2016-07-09 - 2016-07-10</p>
</th>
<th><span class="badge bkgcol-wet-asphalt">55</span></th>
</tr>
</thead>
<tbody class="mashed_body">
<tr class="mashed_row">
<td class="bkgcol-sunflower wht-border">
<div class="date_cell">
<span class="asphalt long_date">Sat</span><span class="white day">Jul 09, 2016</span>
</div>
</td>
<td class="linked-title dark unpadded">
<div class="cell_link">
link 1
</div>
</td>
<td class="small-cell">
<i class="fa fa-arrow-right"></i>
</td></tr><tr class="mashed_row">
<td class="bkgcol-sunflower wht-border">
<div class="date_cell">
<span class="asphalt long_date">Sat</span>
<span class="white day">Jul 09, 2016</span>
</div>
</td>
<td class="linked-title dark unpadded">
<div class="cell_link">
Link 2
</div>
</td>
<td class="small-cell">
<i class="fa fa-arrow-right"></i>
</td>
</tr>
<tr class="mashed_row">
<td class="bkgcol-sunflower wht-border">
<div class="date_cell">
<span class="asphalt long_date">Sat</span>
<span class="white day">Jul 09, 2016</span>
</div>
</td>
<td class="linked-title dark unpadded">
<div class="cell_link">
Link 3
</div>
</td>
<td class="small-cell">
<i class="fa fa-arrow-right"></i>
</td>
</tr>
</tbody>
</table>
<script type="text/javascript">
$(document).ready(function() {
attachEvents();
});
function attachEvents() {
var selClass = 'highlight';
$('#mashed_tab tr a').click(function() {
$(this).parent().parent().removeClass(selClass);
$(this).parent().parent().addClass(selClass);
});
};
</script>
Try something like this in your on click function and let me know.
$('tr a').click(function() {
$("#mashed_tab tr").find("." + selClass).removeClass(selClass);
$(this).parent().parent().addClass(selClass); });
Related
i am new in both php and jquery. i want to use span to hide and show content in html and php. can i use jquery? if yes, what should i do? i already put the jquery script to the bottom of page. this is my code :
<!-- reply -->
<span title="fas fa-reply" name="reply" data-id="1"
</span>
<!-- if span clicked show all these data... -->
<table class="table table-borderless" style="margin-top:50px;">
<thead class="bg-secondary pb-0">
<tr>
<th colspan="3" class="pb-0">
<p class="test text-light">Creating Reply <?php echo $rowAllPost["id"]; ?>
</p></th>
<th class="pb-0 text-right">
</th>
</tr>
</thead>
<th scope="row" style="width:15rem!important;">
<img src="<?php echo $rowViewUserNow["picture"];?>" class="rounded-circle" style=height:93px;width:81px;><br>
<p class="ml-3"> Online</p>
<p class="ml-2"> <?php echo $rowViewUserNow["username"];?>
</p>
<i class="fas fa-info-circle pr-2 pt-2"></i>Active
<td colspan="3" class="text-justify">
<form action="controller/doCheckPost.php" method="post">
<textarea name="description" class="form-control"></textarea>
</td>
</tr>
<tr class="bg-secondary pb-0" >
<th colspan="3" class="pb-0">
<button title="Cancel" class="btn" type="submit" name="cancel"><i class="fas fa-times"></i></th></button>
<th class= "pb-0 text-right">
<button title="Submit" class="btn" name="submit"><i class="fas fa-check"></i></button>
</form>
</th>
</th>
</tr>
</div>
</tbody>
</table>
The best way would be to first give an id to both the span and table elements. Then you can use an event handler in jQuery like this:
$('#spanId').on('click', function() {
$('#tableId').toggle();
});
Toggle will show the element if it's hidden and hide it if it's visible.
i have created a table (using datatables) and in the table a few actions. in the table i have a button to do a function "delete", also using datatables i get pagination.. So for example i am at page 5, and i want to delete a row when i click delete it refreshes the page and goes back to page no 1. How can i make it remain at page 5 after the action delete? Below are my table and controller function
viewStatistics.blade:
<table class="table table-hover demo-table-search table-responsive-block alt-table" id="tableWithSearch">
<thead>
<tr>
<th class="text-center" style="width:80px;">ID</th>
<th class="text-center">Date</th>
<th class="text-center">Question <br> Asked</th>
<th class="text-center">Low <br> Confidence</th>
<th class="text-center">No <br> Answer</th>
<th class="text-center">Missing <br> Intent</th>
<th class="text-center">Webhook <br> Fail</th>
<th class="text-center">Status</th>
<th class="text-center">Action</th>
</tr>
</thead>
<tbody>
#foreach($data as $sessionID => $value)
<tr>
<td class="text-center">{{$value['identifier']}}</td>
<td class="text-center">{{date("d M", strtotime($value['dateAccess']))}}</td>
<td class="text-center">{{$value['total']}}</td> <!-- question asked -->
<td class="text-center">{{$value['low confidence']}}</td> <!-- low confidence -->
<td class="text-center">{{$value['no answer']}}</td> <!-- no answer -->
<td class="text-center">{{$value['missing intent']}}</td> <!-- missing intent -->
<td class="text-center">{{$value['webhook fail']}}</td> <!-- webhook fail -->
<td class="text-center" style="{{$value['status'] == 'Reviewed' ? 'color:green' : 'color:red'}}">
{{$value['status']}}
#if($value['status'] == 'Pending')
<input type="checkbox" name="check" class="check" value="{{$sessionID}}">
#endif
</td> <!-- status -->
<td class="text-center">
<div class="btn-group">
<button type="button" class="btn alt-btn alt-btn-black dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Manage</button>
<ul class="dropdown-menu">
<li>
View
</li>
<li>
Delete
</li>
#if($value['status'] == 'Pending')
<li>
Mark as Done
</li>
#endif
</ul>
</div>
</td> <!-- action -->
</tr>
#endforeach
</tbody>
</table>
Controller:
public function deleteStatistics($companyID, $sessionID)
{
DiraChatLog::where('company_id', $companyID)->where('sessionID', $sessionID)->delete();
return redirect(action('AltHr\Chatbot\TrackerController#viewStatistics', compact('companyID')))->with('notification',[
'status' => 'success',
'title' => 'Statistics Deleted',
'message' => 'The Statistics have been deleted.'
]);
}
There is an option named stateSave in jquery datatables. Please check the code below:
$('#example').dataTable({ stateSave: true });
When I click on "lock" I want only the line where I clicked to change the status to true and the lock be locked. When I click on "unlock" I want only the line where I clicked to change the status to false and the released lock.
In my current code:
when I click on a lock on the first line your status changes and also the lock, but the lock of the other lines also change. I need help to fix this.
There is also another thing that I think I should use ajax. When the table is generated and executed for the first time all status will be in false and the lock "open" To mark a line as locked (lock) the status will make is true, and I need to send this "true" pro database and save it through a php script, so that, to reload the page status I had changed continues saved.
I am using the following plugin Context menu:
For better visualization, I put my code in pastebin.
change.js
$(function(){
$.contextMenu({
selector: '.context-menu-one',
items: {
"block": {
name: "Lock",
icon: "edit",
callback: function(key, options){
var m = $(this).text();
var set = block(m, $(this)); // passando - this - como parâmetro de função
}
},
"sep1": "----------",
"unblock": {
name: "Unlock",
icon: "cut",
callback: function(key, options){
var m = $(this).text();
var set = unblock(m, $(this)); // passando - this - como parâmetro de função
}
}
}
});
});
function block(x, thisObj)
{
if (x === "false")
x = "true";
thisObj.html(x);
$(".lock1").html('<i class="fa fa-unlock" aria-hidden="true"></i>');
}
function unblock(x, thisObj)
{
if (x === "true")
x = "false";
thisObj.html(x);
$(".lock1").html('<i class="fa fa-lock" aria-hidden="true"></i>');
}
PasteBin.
network.php
<?php
$con = mysqli_connect("localhost", "root", "", "mydb2");
?>
<ul class="breadcrumb">
<li>Ir para</li>
<li>dashboard</li>
</ul>
<div class="page-content-wrap">
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
<div class="page-title">
<h2><span class="fa fa-hand-spock-o"></span> - Virtual Private Network</h2>
<p id="test">abc</p>
</div>
</div>
<div class="panel-body">
<div class="table-responsive">
<table class="table datatable table-striped">
<thead>
<tr>
<th>Common Name</th>
<th>Real Address</th>
<th>Virtual Address</th>
<th>Bytes Sent</th>
<th>Bytes Received</th>
<th>Since</th>
<th>Status</th>
<th>Blocked</th> <!--inserir a imagem de cliente bloqueado ou não -->
</tr>
</thead>
<tbody>
<tr>
<td class="context-menu-one">orion</td>
<td class="context-menu-one">177.43.212.110</td>
<td class="context-menu-one">172.16.191.145</td>
<td class="context-menu-one">872199</td>
<td class="context-menu-one">860412</td>
<td class="context-menu-one">Wed May 25 07:22:52 2016</td>
<td class="context-menu-one">false</td>
<td class="lock1"><i class="fa fa-unlock" aria-hidden="true"></i></td>
</tr>
<tr>
<td class="context-menu-one">elgin</td>
<td class="context-menu-one">189.10.58.244</td>
<td class="context-menu-one">172.16.6.210</td>
<td class="context-menu-one">301365</td>
<td class="context-menu-one">250459</td>
<td class="context-menu-one">Wed May 25 07:01:37 2016</td>
<td class="context-menu-one">false</td>
<td class="lock1"><i class="fa fa-unlock" aria-hidden="true"></i></td>
</tr>
<tr>
<td class="context-menu-one">databits</td>
<td class="context-menu-one">187.17.235.203</td>
<td class="context-menu-one">172.16.136.217</td>
<td class="context-menu-one">459833</td>
<td class="context-menu-one">409771</td>
<td class="context-menu-one">Wed May 25 06:09:01 2016</td>
<td class="context-menu-one">false</td>
<td class="lock1"><i class="fa fa-unlock" aria-hidden="true"></i></td>
</tr>
<tr>
<td class="context-menu-one">proficio</td>
<td class="context-menu-one">179.213.177.117</td>
<td class="context-menu-one">172.16.196.93</td>
<td class="context-menu-one">1083595</td>
<td class="context-menu-one">945154</td>
<td class="context-menu-one">Tue May 24 21:36:21 2016</td>
<td class="context-menu-one">false</td>
<td class="lock1"><i class="fa fa-unlock" aria-hidden="true"></i></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
?>
PasteBin.
My table:
The "lock" option:
It was a fun one!
First, I changed the position of context-menu-one class for the parent's.
And delegated the action on it's tds by this: selector: '.context-menu-one td'.
Because it makes less elements to "watch" for jQuery... And cleans the code.
Then... I modified the callback functions in your items object.
I played with .parent(), siblings() and prev() to target all the right elements.
HTML:
<ul class="breadcrumb">
<li>Ir para</li>
<li>dashboard</li>
</ul>
<div class="page-content-wrap">
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
<div class="page-title">
<h2><span class="fa fa-hand-spock-o"></span> - Virtual Private Network</h2>
<p id="test">abc</p>
</div>
</div>
<div class="panel-body">
<div class="table-responsive">
<table class="table datatable table-striped">
<thead>
<tr>
<th>Common Name</th>
<th>Real Address</th>
<th>Virtual Address</th>
<th>Bytes Sent</th>
<th>Bytes Received</th>
<th>Since</th>
<th>Status</th>
<th>Blocked</th> <!--inserir a imagem de cliente bloqueado ou não -->
</tr>
</thead>
<tbody>
<tr class="context-menu-one row">
<td>orion</td>
<td>177.43.212.110</td>
<td>172.16.191.145</td>
<td>872199</td>
<td>860412</td>
<td>Wed May 25 07:22:52 2016</td>
<td>false</td>
<td class="lock1"><i class="fa fa-unlock" aria-hidden="true"></i></td>
</tr>
<tr class="context-menu-one row">
<td>elgin</td>
<td>189.10.58.244</td>
<td>172.16.6.210</td>
<td>301365</td>
<td>250459</td>
<td>Wed May 25 07:01:37 2016</td>
<td>false</td>
<td class="lock1"><i class="fa fa-unlock" aria-hidden="true"></i></td>
</tr>
<tr class="context-menu-one row">
<td>databits</td>
<td>187.17.235.203</td>
<td>172.16.136.217</td>
<td>459833</td>
<td>409771</td>
<td>Wed May 25 06:09:01 2016</td>
<td>false</td>
<td class="lock1"><i class="fa fa-unlock" aria-hidden="true"></i></td>
</tr>
<tr class="context-menu-one row">
<td>proficio</td>
<td>179.213.177.117</td>
<td>172.16.196.93</td>
<td>1083595</td>
<td>945154</td>
<td>Tue May 24 21:36:21 2016</td>
<td>false</td>
<td class="lock1"><i class="fa fa-unlock" aria-hidden="true"></i></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
JavaScript:
$(function(){
$.contextMenu({
selector: '.context-menu-one td',
items: {
"block": {
name: "Lock",
icon: "edit",
callback: function(key, options){
console.log("HERE");
if ($(this).parent().hasClass("row")){
console.log("HERE IF");
thisRowPadlock = $(this).siblings(".lock1");
var m = $(this).siblings(".lock1").prev().text();
console.log(m);
var set = block(m, thisRowPadlock, $(this).siblings(".lock1").prev()); // passando - this - como parâmetro de função
}
}
},
"sep1": "----------",
"unblock": {
name: "Unlock",
icon: "cut",
callback: function(key, options){
console.log("THERE");
if ($(this).parent().hasClass("row")){
thisRowPadlock = $(this).siblings("lock1");
var m = $(this).siblings(".lock1").prev().text();
console.log(m);
var set = unblock(m, thisRowPadlock, $(this).siblings(".lock1").prev()); // passando - this - como parâmetro de função
}
}
}
}
});
});
function block(x, padlock, thisObj)
{
console.log("Function block");
if (x === "false")
x = "true";
thisObj.html(x);
$(padlock).html('<i class="fa fa-unlock" aria-hidden="true"></i>');
}
function unblock(x, padlock, thisObj)
{
console.log("Function unblock");
if (x === "true")
x = "false";
thisObj.html(x);
$(padlock).html('<i class="fa fa-lock" aria-hidden="true"></i>');
}
And a working Fiddle (with some missing CSS, sorry).
I have a table in my form which gets its data from a MYSQL database. I am trying to make it dynamic by allow the user to add more information, however I'm having difficulties in adding an extra row directly under the last row of the query.This is the code i have so far and my attempt at adding a new row using JQuery:
<h4>Manage Courses</h4>
<div class="container">
<div class = "container-fluid">
<div id = "table_container" style="margin-top:50px;" class="mainbox col-md-6">
<div class="row clearfix">
<div class="col-md-12">
<table class="table table-bordered table-hover" id="tab_logic">
<thead>
<tr >
<!-- <th class="text-center">
#
</th> -->
<th class="text-center">
Course Code
</th>
<th class="text-center">
Course Title
</th>
<!-- <th class="text-center">
Edit
</th>
<th class="text-center">
Delete
</th> -->
</tr>
</thead>
<?php foreach ($courses as $row) {
echo "<tr><td>";
echo $row['course_code'];
echo "</td><td>";
echo $row['course_title'];
echo "</td>";
echo "</tr>"; }
?>
<tbody>
<tr id='addr0'>
<td>
1
</td>
<td>
<input type="text" name='code' placeholder='Code' class="form-control"/>
</td>
<td>
<input type="text" name='title' placeholder='Title' class="form-control"/>
</td>
<td>
<p
data-placement="top"
title="Edit"></a>
<button class="btn btn-primary btn-xs"
data-title="Edit"
data-toggle="modal"
data-target="#edit" >
<span class="glyphicon glyphicon-pencil"></span></button></p>
</td>
<td>
<p
data-placement="top"
data-toggle="tooltip"
style="margin-left:5px"
itle="Delete">
<button class="btn btn-danger btn-xs"
data-title="Delete"
data-toggle="modal"
data-target="#delete" >
<span class="glyphicon glyphicon-trash"></span></button></p>
</td>
</tr>
<tr id='addr1'></tr>
</tbody>
</table>
</div>
</div>
<a id="add_row" class="btn btn-default pull-left">Add Row
<span class="glyphicon glyphicon-plus"></span>
</a>
<a id='delete_row' class="pull-left btn btn-default">Delete Row
<span class="glyphicon glyphicon-trash"></span>
</a>
</div>
</div>
</div>
and this is the Jquery to support the add and delete buttons:
$(document).ready(function(){
var i=1;
$("#add_row").click(function(){
$('#addr'+i).html("<td>"+ (i+1) +"</td><td><input name='code"+i+"' type='text' placeholder='Code' class='form-control input-md' /> </td><td><input name='title"+i+"' type='text' placeholder='Title' class='form-control input-md'></td>");
$('#tab_logic').append('<tr id="addr'+(i+1)+'"></tr>');
i++;
});
$("#delete_row").click(function(){
if(i>1){
$("#addr"+(i-1)).html('');
i--;
}
});
});
The code adds one row underneath the last row but them adds the second row above it for some reason.
Another issue i am encountering is the ability to replicate the glyphicons for the delete and edit for each row. I would really like these to be added for each row and for the new rows being added.
Any help would be much appreciated! :)
In the html you provided there is no "#tab_logic". You are also creating rows outside of the <tbody> and <thead> options. You also are not creating html for the glyphicons in your jQuery function.
Edit: sorry there is a tab_logic. But, you need to make sure you include the html for the glypicon. A better way to do this might be to clone an existing element and insert it.
I'm not seeing the additional row being inserted as you describe:
http://jsfiddle.net/pekv2tx0/
Also: fix your HTML, this is what is causing the problems, note the closing anchor tag with no body, inside of a p tag, and you have an empty row, so it's not inserting an extra, it's already in the html:
<p
data-placement="top"
title="Edit"></a>
<button class="btn btn-primary btn-xs"
data-title="Edit"
data-toggle="modal"
data-target="#edit" >
<span class="glyphicon glyphicon-pencil"></span></button></p>
</td>
<tr id='addr1'></tr>
inside your click function, try appending an entire row to the tbody:
$("#add_row").click(function(){
$('#tab_logic tbody').append("<tr><td>"+ (i+1) +"</td><td><input name='code"+i+"' type='text' placeholder='Code' class='form-control input-md' /> </td><td><input name='title"+i+"' type='text' placeholder='Title' class='form-control input-md'></td></tr>");
i++;
});
How can i pass data from my table to a pop-up.
This is how i did it in my table:
I populate the table from my database using controllers and models
<table class="table table-striped table-checkable" id="demo-dtable-02" aria-describedby="DataTables_Table_0_info">
<thead>
<tr>
<th class="sorting" role="columnheader" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1" aria-label="Subject: activate to sort column ascending" style="width: 220px;">??</th><th class="sorting" role="columnheader" tabindex="0" aria-controls="DataTables_Table_0" rowspan="1" colspan="1" aria-label="Date: activate to sort column ascending" style="width: 79px;">??</th>
</tr>
</thead>
<tbody role="alert" aria-live="polite" aria-relevant="all">
<?php
foreach ($my_page_data['text_list']as $text_list_key => $text_list_data){
?>
<tr class="odd">
<td class=" "><a href="#" onclick="viewText(<?php echo $text_list_data['id'] ?>)" data-toggle="modal" data-target="#view-text" ><?php $msg = $text_list_data['msg']; ?></a></td>
<div id="<?php echo $inbox_list_data['id'] ?>" data-content="<?php $msg = $inbox_list_data['message']?>"></div> <!-- i used this as a hidden div for the data to be passed because i dont know other ways -->
<td class=" "><?php $date = $text_list_data['date_updated'];?></td>
</tr>
<?php } ?>
</tbody>
</table>
Then i used a script to pass the data...
<script>
function viewInbox(id){
$('#inbox-message-body').text($('#'+id).attr('data-content'));
}
</script>
And then the the clicked data will be displayed here:
<div class="modal-body">
<div class=" . . .">
<div class="..">
<span class="view-label">From:</span> MY OTHER DATA <!--TODO: -->
<br>
<span class="view-label">To:</span> MY DATA<!--TODO: -->
<br>
</div>
</div>
<!--TODO: Message body--> I
<span id="message-body" class="span8"></span>
</div>
This code are just in one file.
The page im creating is like. I have a table of messages. Then to view message is to click it and a pop-up will appear.
Any insights?
Your help is greatly appreaciated.
The way i do it is i assign modal template to a different controller, and then call it via ajax request like this.
$(".modalCaller").click(function(){
$.ajax({
type: POST,
url: "/insert/modal/controller/here",
data: {id: $(this).data("id")},
success: function(data){
data.appendTo("body").modal("show");
}
})
});
And just drop your modal into another view.