3
The future table data will be shown through the code below:
<?php
while($linhaAssociativa = mysqli_fetch_assoc($query))
{ ?>
<tr>
<td class="cmenu2"><?php echo $linhaAssociativa["CommonName"]; ?></td>
<td><?php echo $linhaAssociativa["RealAddress"]?></td>
<td><?php echo $linhaAssociativa["BytesSent"]?></td>
<td><?php echo $linhaAssociativa["BytesReceived"]?></td>
<td><?php echo $linhaAssociativa["VirtualAddress"]?></td>
<td><?php echo $linhaAssociativa["Since"]?></td>
<td><?php echo $linhaAssociativa["Status"]?></td>
</tr>
<?php
} ?>
Where each line is one client and has a status column(is the last column of each row) with the value 0 or 1.
I’m wearing a plugin of contextmenu to create a menu Lock/Unlock by clicking on the first column of each row and a plugin of confirm by clicking lock (image 3).
What I’m trying to do: when right-clicking on a line, if the option is block off the status it was 0 will turn 1, case unlock 1 will turn 0. Later I’ll get the information from td that will save the value of status (0 or 1) and play in a database - but this is apparently easy. What I can’t do: If I right click on Garret Winters the plugin contextmenu will open and if clicked on lock, 0 will turn 1. However I do not know repeat the logic for all other lines (Winters and all other lines below).
The code of functions:
$(function() {
$.contextMenu({
selector: 'NOME DO SELETOR',
callback: function(key, options) {
var m = "clicked: " + key;
window.console && console.log(m) || alert(m);
},
items: {
"bloquear": {name: "Bloquear", icon: "edit"},
"desbloquear": {name: "Desbloquear", icon: "cut"},
}
});
$('.context-menu-one').on('click', function(e){
console.log('clicked', this);
})
});
And
$.confirm({
title:"Você tem certeza?",
content:"Você REALMENTE tem certeza que quer bloquear este cliente?",
confirmButton: 'Eu quero',
cancelButton: 'Não, nunca!',
confirm: function(){
$.alert('Ok... Como o senhor quiser');
}
});
Trying to make it as clear as possible - Let’s say the table has 10 rows, and each row contains a NAME column and a STATUS column (by default with value 0). If I click on the first line with the right button and go on lock, it will change the STATUS (the class td cmenu2) to 1. HOWEVER if I put the second row td also as cmenu2 class and try to apply logic as I showed in photos/code, and right-click on line two, go on lock, it will change the status of line one and not of the two!
The selector used is the class
.cmenu2
?– StillBuggin
@Eduardoalmeida Then, inside the while, where it is created tr and td’s, the last td has as class cmenu2. Only if all rows (are more than 200 rows) have the last column (Status) as class cmenu2, when right-clicking and going to lock, it will change the value from 0 to 1 in all columns Status and all rows..
– Cesar Augusto
For me it worked correctly. The problem may be the use with the Datatables plugin.
– StillBuggin
@Eduardoalmeida what exactly worked for you brother? See again what I’m not able to do... I don’t think I can explain it better.
– Cesar Augusto
"But I don’t know how to repeat the logic for all the other lines". It worked like
.context-menu-one
, https://swisnl.github.io/jQuery-contextMenu/demo.html– StillBuggin
I entered the code I used for testing. In all rows generated the context menu appears when I right-click.
– StillBuggin