Issue in table sorting inside expandable table in codeigniter - javascript

I want to sort my table data in expandable table view, so I tried the below code:
Code Link
and my view is as in the below image
When I use this code and put in my site, it is not working in this type of view like expandable table view. The sorting is not being performed in the expandable table view. Any idea how can I make it work?
EDIT
stupidtable.js
// Stupid jQuery table plugin.
(function($) {
$.fn.stupidtable = function(sortFns) {
return this.each(function() {
var $table = $(this);
sortFns = sortFns || {};
sortFns = $.extend({}, $.fn.stupidtable.default_sort_fns, sortFns);
$table.data('sortFns', sortFns);
$table.on("click.stupidtable", "thead th", function() {
$(this).stupidsort();
});
});
};
// Expects $("#mytable").stupidtable() to have already been called.
// Call on a table header.
$.fn.stupidsort = function(force_direction){
var $this_th = $(this);
var th_index = 0; // we'll increment this soon
var dir = $.fn.stupidtable.dir;
var $table = $this_th.closest("table");
var datatype = $this_th.data("sort") || null;
// No datatype? Nothing to do.
if (datatype === null) {
return;
}
// Account for colspans
$this_th.parents("tr").find("th").slice(0, $(this).index()).each(function() {
var cols = $(this).attr("colspan") || 1;
th_index += parseInt(cols,10);
});
var sort_dir;
if(arguments.length == 1){
sort_dir = force_direction;
}
else{
sort_dir = force_direction || $this_th.data("sort-default") || dir.ASC;
if ($this_th.data("sort-dir"))
sort_dir = $this_th.data("sort-dir") === dir.ASC ? dir.DESC : dir.ASC;
}
$table.trigger("beforetablesort", {column: th_index, direction: sort_dir});
// More reliable method of forcing a redraw
$table.css("display");
// Run sorting asynchronously on a timout to force browser redraw after
// `beforetablesort` callback. Also avoids locking up the browser too much.
setTimeout(function() {
// Gather the elements for this column
var column = [];
var sortFns = $table.data('sortFns');
var sortMethod = sortFns[datatype];
var trs = $table.children("tbody").children("tr");
// Extract the data for the column that needs to be sorted and pair it up
// with the TR itself into a tuple. This way sorting the values will
// incidentally sort the trs.
trs.each(function(index,tr) {
var $e = $(tr).children().eq(th_index);
var sort_val = $e.data("sort-value");
// Store and read from the .data cache for display text only sorts
// instead of looking through the DOM every time
if(typeof(sort_val) === "undefined"){
var txt = $e.text();
$e.data('sort-value', txt);
sort_val = txt;
}
column.push([sort_val, tr]);
});
// Sort by the data-order-by value
column.sort(function(a, b) { return sortMethod(a[0], b[0]); });
if (sort_dir != dir.ASC)
column.reverse();
// Replace the content of tbody with the sorted rows. Strangely
// enough, .append accomplishes this for us.
trs = $.map(column, function(kv) { return kv[1]; });
$table.children("tbody").append(trs);
// Reset siblings
$table.find("th").data("sort-dir", null).removeClass("sorting-desc sorting-asc");
$this_th.data("sort-dir", sort_dir).addClass("sorting-"+sort_dir);
$table.trigger("aftertablesort", {column: th_index, direction: sort_dir});
$table.css("display");
}, 10);
return $this_th;
};
// Call on a sortable td to update its value in the sort. This should be the
// only mechanism used to update a cell's sort value. If your display value is
// different from your sort value, use jQuery's .text() or .html() to update
// the td contents, Assumes stupidtable has already been called for the table.
$.fn.updateSortVal = function(new_sort_val){
var $this_td = $(this);
if($this_td.is('[data-sort-value]')){
// For visual consistency with the .data cache
$this_td.attr('data-sort-value', new_sort_val);
}
$this_td.data("sort-value", new_sort_val);
return $this_td;
};
// ------------------------------------------------------------------
// Default settings
// ------------------------------------------------------------------
$.fn.stupidtable.dir = {ASC: "asc", DESC: "desc"};
$.fn.stupidtable.default_sort_fns = {
"int": function(a, b) {
return parseInt(a, 10) - parseInt(b, 10);
},
"float": function(a, b) {
return parseFloat(a) - parseFloat(b);
},
"string": function(a, b) {
return a.localeCompare(b);
},
"string-ins": function(a, b) {
a = a.toLocaleLowerCase();
b = b.toLocaleLowerCase();
return a.localeCompare(b);
}
};
})(jQuery);
my Script code
<script>
$(function(){
// Helper function to convert a string of the form "Mar 15, 1987" into a Date object.
var date_from_string = function(str) {
var months = ["jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec"];
var pattern = "^([a-zA-Z]{3})\\s*(\\d{1,2}),\\s*(\\d{4})$";
var re = new RegExp(pattern);
var DateParts = re.exec(str).slice(1);
var Year = DateParts[2];
var Month = $.inArray(DateParts[0].toLowerCase(), months);
var Day = DateParts[1];
return new Date(Year, Month, Day);
}
var table = $("table").stupidtable({
"date": function(a,b) {
// Get these into date objects for comparison.
aDate = date_from_string(angel);
bDate = date_from_string(beer);
return aDate - bDate;
}
});
table.on("beforetablesort", function (event, data) {
// Apply a "disabled" look to the table while sorting.
// Using addClass for "testing" as it takes slightly longer to render.
$("#msg").text("Sorting...");
$("table").addClass("disabled");
});
table.on("aftertablesort", function (event, data) {
// Reset loading message.
$("#msg").html(" ");
$("table").removeClass("disabled");
var th = $(this).find("th");
th.find(".arrow").remove();
var dir = $.fn.stupidtable.dir;
var arrow = data.direction === dir.ASC ? "↑" : "↓";
th.eq(data.column).append('<span class="arrow">' + arrow +'</span>');
});
});
</script>
When I run the above code and expand my view, in my stupidtable.js file there is code like
"string": function(a, b) {
return a.localeCompare(b);
},
In this code a.localeCompare(b); is getting null in expandable table view so it is not sorting well, and I also want sorting inside the data which table is expanded. Any idea how I can solve this issue?
html code
<table id="property" class="hometable table-bordered">
<thead>
<tr>
<th >#</th>
<th >Image</th>
<th width="12%" >
<a href="<?php echo base_url();?>property/propertylist?field=p_name&sort_by=<?php echo $sort;?>">
Property Name
<? if($sort == 'ASC' && $_GET['field']=='p_name') echo '<img src='.base_url("assets/plugins/data-tables/images/sort_asc.png").'>'; else if($sort == 'DESC'&& $_GET['field']=='p_name') { echo '<img src='.base_url("assets/plugins/data-tables/images/sort_desc.png").'>'; } else {echo '<img src='.base_url("assets/plugins/data-tables/images/sort_both.png").'>';}?>
</a>
</th>
<th >Address</th>
<th >
<a href="<?php echo base_url();?>property/propertylist?field=p_city&sort_by=<?php echo $sort;?>">
City
<? if($sort == 'ASC' && $_GET['field']=='p_city') echo '<img src='.base_url("assets/plugins/data-tables/images/sort_asc.png").'>'; else if($sort == 'DESC' && $_GET['field']=='p_city') { echo '<img src='.base_url("assets/plugins/data-tables/images/sort_desc.png").'>'; } else {echo '<img src='.base_url("assets/plugins/data-tables/images/sort_both.png").'>';}?>
</a>
</th>
<th >
<a href="<?php echo base_url();?>property/propertylist?field=p_state&sort_by=<?php echo $sort;?>">
State
<? if($sort == 'ASC' && $_GET['field']=='p_state') echo '<img src='.base_url("assets/plugins/data-tables/images/sort_asc.png").'>'; else if($sort == 'DESC' && $_GET['field']=='p_state') { echo '<img src='.base_url("assets/plugins/data-tables/images/sort_desc.png").'>'; } else {echo '<img src='.base_url("assets/plugins/data-tables/images/sort_both.png").'>';}?>
</a>
</th>
<th width="9%" >
<a href="<?php echo base_url();?>property/propertylist?field=p_country&sort_by=<?php echo $sort;?>">
Country
<? if($sort == 'ASC' && $_GET['field']=='p_country') echo '<img src='.base_url("assets/plugins/data-tables/images/sort_asc.png").'>'; else if($sort == 'DESC' && $_GET['field']=='p_country') { echo '<img src='.base_url("assets/plugins/data-tables/images/sort_desc.png").'>'; } else {echo '<img src='.base_url("assets/plugins/data-tables/images/sort_both.png").'>';}?>
</a>
</th>
<th >Zipcode</th>
<th colspan="2" >
<a href="<?php echo base_url();?>property/propertylist?field=unit_type&sort_by=<?php echo $sort;?>">
Property Type
<? if($sort == 'ASC' && $_GET['field']=='unit_type') echo '<img src='.base_url("assets/plugins/data-tables/images/sort_asc.png").'>'; else if($sort == 'DESC' && $_GET['field']=='unit_type') { echo '<img src='.base_url("assets/plugins/data-tables/images/sort_desc.png").'>'; } else {echo '<img src='.base_url("assets/plugins/data-tables/images/sort_both.png").'>';}?>
</a>
</th>
<th >Tenants</th>
<? if(!empty($query1)){?>
<th >Edit </th>
<th >Copy </th>
<th >Delete </th>
<? } else {?>
<th >Edit </th>
<th >Copy</th>
<th >Delete</th>
<? } ?>
</tr>
</thead>
<? if(empty($detail)) { ?>
<tr>
<td colspan="14">
<div class="tblalert alert-danger"><!--<button class="close" data-close="alert"></button>--><span>No property available.</span></div>
</td>
</tr>
<?php }else {
$i = 0;
foreach($detail as $pro) {
$i++;
?>
<tr id="trarrow<? echo $i;?>">
<? $admindata = $this->session->userdata('id');
$query = $this->db->query('SELECT r_country,amt_format FROM register where id="'.$admindata.'"');
foreach ($query->result() as $row)
{ $currency = $row->r_country ;
$amt_format = $row->amt_format ;
}
$curren = $this->db->query('SELECT * FROM country where id="'.$currency.'"');
foreach ($curren->result() as $row)
{ $curr = $row->currency ;
}
$unit = $this->db->query("SELECT * FROM property_unit WHERE p_id = '".$pro['p_id']."'");
$unitid = count($unit->result_array());
?>
<?php /*?><?php if($pro['unit_type'] == '0'){ ?>
<td align="center" style="cursor:pointer"><div class="arrow" id="arimg<?php echo $i?>"></div></td>
<? } else {?>
<td align="center" id="arrow<?php echo $i?>" onClick="trshow(<?php echo $i?>);" style="cursor:pointer"><div class="arrow" id="arimg<?php echo $i?>"></div></td>
<? } ?><?php */?>
<td><?php echo $i; ?></td>
<td align="center">
<? if(!empty($pro['p_path'])) { ?>
<a class="fancybox fancyboxiframe" href="<?php echo base_url('property/popup/'.$pro['p_id']);?>">
<img class="img-polaroid" src="http://worldofrental.s3.amazonaws.com/<? echo $pro['p_path'];?>" alt="Please Upload Image" width="50" height="50">
<? } else {?>
<img class="img-polaroid" src=<? echo base_url('upload/tenants/app_logo.png');?> alt="Upload Image" width="50" height="50">
<? }
?>
</a>
</td>
<td >
<a href="<? echo base_url('property/propertyedit/'.$pro['p_id']);?>">
<?php echo $pro['p_name']; ?>
</a>
</td>
<td ><?php echo $pro['p_address']; ?></td>
<td><?php echo $pro['p_city']; ?></td>
<td>
<?php $statename = $this->db->query("SELECT state_name FROM state WHERE state_id = '".$pro['p_state']."'"); $state_name = $statename->result_array(); echo $state_name[0]['state_name']; ?>
</td>
<td ><?php echo $pro['name']; ?></td>
<td><?php echo $pro['p_zipcode']; ?></td>
<?php if($pro['unit_type'] == '0'){ ?>
<td style="border-right:solid 0px !important; "></td>
<td align="right" style="border-left:solid 0px !important; "><?php echo 'Single Unit'; ?></td>
<? } else {?>
<td style="border-right:solid 0px !important; cursor:pointer; " id="arrow<?php echo $i?>" onClick="trshow(<?php echo $i?>);" >
<div class="arrow" id="arimg<?php echo $i?>"></div>
</td>
<td align="right" style="cursor:pointer; border-left:solid 0px !important; " id="arrow<?php echo $i?>" onClick="trshow(<?php echo $i?>);" >
<div id="arimg<?php echo $i?>"></div>
<a class="btn default btn-xs blue" >
<? echo 'Multi Unit' .' '.'('.$unitid.')';?>
</a>
<? } ?>
</a>
</td>
<td>
<a class="btn default btn-xs yellow" data-toggle="modal" onClick="Viewtenants(<? echo $pro['p_id'];?>); return false;" title="View Tenants" href="#myproperty-<? echo $pro['p_id'];?>">
View Tenants
</a>
</td>
<div id="myproperty-<? echo $pro['p_id'];?>" class="modal fade"></div>
<? if(!empty($query1)){?>
<td>
<a class="btn blue disabled" title="your service has been canceled" href="<?php echo base_url('property/propertyedit/'.$pro['p_id']);?>">
<i class="fa fa-edit"></i> Edit
</a>
</td>
<div id="myModal-<? //echo $pro->pid;?>" class="modal fade"></div>
<td>
<a class="btn green disabled" title="your service has been canceled" href="<?php echo base_url('property/copydata/'.$pro['p_id']);?>">
<i class="fa fa-copy"></i> Copy
</a>
</td>
<!--<td class="status" align="center"><a style="cursor:pointer" title="Trash" onClick="CheckUsername(<? echo $pro['p_id'];?>); return false;" id="status">
<div id="status-<? echo $pro['p_id'];?>">
</div> <i class="fa fa-trash-o"></i> Trash</a></td>-->
<td>
<a class="delete btn red disabled btn-xs black delete-confirm" delete-url="<?php echo base_url('property/status_change/'.$pro['p_id']);?>" data-confirm="Are you sure you want to trash this property?" title="your service has been canceled">
<i class="fa fa-trash-o"></i> Delete
</a>
</td>
<? } else {?>
<td>
<a class="btn default btn-xs blue" title="Edit/View" href="<?php echo base_url('property/propertyedit/'.$pro['p_id']);?>">
<i class="fa fa-edit"></i> Edit
</a>
</td>
<div id="myModal-<? //echo $pro->pid;?>" class="modal fade"></div>
<td align="center">
<a class="btn default btn-xs green" title="Edit/View" href="<?php echo base_url('property/copydata/'.$pro['p_id']);?>">
<i class="fa fa-copy"></i> Copy
</a>
</td>
<td>
<a class="btn red" data-toggle="modal" onClick="ViewStore(<? echo $pro['p_id'];?>); return false;" title="Delete" href="#myModal-<? echo $pro['p_id'];?>">
<i class="fa fa-trash-o"></i>
<font size="-1"> Delete</font>
</a>
</td>
<div id="myModal-<? echo $pro['p_id'];?>" class="modal fade"></div>
<? } ?>
</tr>
<tr id="subtr<?php echo $i; ?>">
<td colspan="14">
<? $unit_info = $this->db->query("SELECT * FROM unit_info WHERE p_id = '".$pro['p_id']."' AND isactive = '0' AND unit_id <> '0'");
$result = $unit_info->result_array();
?>
<? if(empty($result)) {?>
<? }else{ ?>
<div class="propertyreport-box">
<div class="title">Property Units</div>
<ul class="finacial-list">
<li><strong>Unit Name</strong></li>
<? foreach($unit_info->result() as $unit){?>
<li><span>
<? $unitname = $this->db->query("SELECT unit_name FROM property_unit WHERE unit_id = '".$unit->unit_id."'"); $unit_name = $unitname->result_array(); echo $unit_name[0]['unit_name'] ;?>
</span></li>
<? } ?>
</ul>
<ul class="finacial-list">
<li><strong>Rent </strong></li>
<? foreach($unit_info->result() as $unit){?>
<li><span>
<? if(!empty($unit->p_rent)){ echo $curr.' '.$unit->p_rent;}else { echo $curr.' '.'0.00';}?>
</span></li>
<? } ?>
</ul>
<ul class="finacial-list">
<li><strong>Bedrooms</strong></li>
<? foreach($unit_info->result() as $unit){?>
<li><span>
<? if(!empty($unit->p_bedroom)){ echo $unit->p_bedroom; }else { echo '0.0';}?>
</span></li>
<? } ?>
</ul>
<ul class="finacial-list">
<li><strong>Bathrooms</strong></li>
<? foreach($unit_info->result() as $unit){?>
<li><span>
<? if(!empty($unit->p_bathroom)){ echo $unit->p_bathroom; }else { echo '0.0';}?>
</span></li>
<? } ?>
</ul>
<ul class="finacial-list">
<li><strong>Sq. Ft</strong></li>
<? foreach($unit_info->result() as $unit){?>
<li><span>
<? if(!empty($unit->p_size)){ echo $unit->p_size; }else { echo '0.00';}?>
</span></li>
<? } ?>
</ul>
<ul class="finacial-list">
<li><strong>Rented</strong></li>
<? foreach($unit_info->result() as $unit){?>
<li><span><? echo $unit->p_isrent;?></span></li>
<? } ?>
</ul>
<ul class="finacial-list">
<li><strong>Tenants</strong></li>
<? foreach($unit_info->result() as $unit){?>
<li><span>
<a class="btn btn-xs yellow" data-toggle="modal" onClick="viewunittenants(<? echo $unit->unit_info_id;?>); return false;" title="Delete" href="#myproperty-<? echo $unit->unit_info_id;?>">
<font size="-2"> View Tenants</font>
</a>
</span></li>
<div id="myproperty-<? echo $unit->unit_info_id;?>" class="modal fade "></div>
<? } ?>
</ul>
<ul class="finacial-list">
<li><strong>Edit</strong></li>
<? foreach($unit_info->result() as $unit){?>
<li><span>
<a class="btn btn-xs yellow" title="Edit/View" href="<?php echo base_url('unit/unitedit/'.$unit->unit_info_id);?>">
<i class="fa fa-edit"></i>
<font size="-2"> Edit</font>
</a>
</span></li>
<? } ?>
</ul>
<ul class="finacial-list">
<li><strong>Delete</strong></li>
<? foreach($unit_info->result() as $unit){?>
<li><span>
<a class="btn btn-xs dark" data-toggle="modal" onClick="ViewStore1(<? echo $unit->unit_info_id;?>); return false;" title="Delete" href="#myModal1-<? echo $unit->unit_info_id;?>">
<i class="fa fa-trash-o"></i>
<font size="-2"> Delete</font>
</a>
</span></li>
<div id="myModal1-<? echo $unit->unit_info_id;?>" class="modal fade "></div>
<? } ?>
</ul>
</div>
<? } ?>
</td>
</tr>
<?php
} }
?>
</table>

You Just try Bootstrap datatables
Click the link

Related

Sweetalert won't show but it will update

I want to show a sweetalert after clicking the set button but it won't function. This is my index page and the set button can function but it won't show the sweet alert. what might be the problem and what should I do?
index.php
<form method='post' action='updataStatus.php'>
<button type='submit' name='but_update' class="inline-block float ml-2 mt-1 btn-group pull-right btn-danger btn-sm">SET</button><button type="submit" id="dataExport" name="dataExport" value="Export to excel" class="inline-block float ml-2 mt-1 btn-group pull-right btn-info btn-sm">Export</button>
<div class="table-responsive">
<br>
<tbody><table class="table table-hover table-bordered" id="sampleTable2">
<thead>
<tr>
<th><input type="checkbox" class="select-all checkbox" name="select-all" id="checkAll" /></th>
<th>Name</th>
<th>Scholarship Program</th>
<th>Course</th>
<th>Semester</th>
<th>Allowance</th>
</tr>
</thead>
<?php
require_once "connection.php";
$query = "SELECT * FROM allowance";
$result = mysqli_query($conn,$query);
while($row = mysqli_fetch_array($result) ){
$id = $row['id'];
$Name = $row['Name'];
$Scholarship = $row['Scholarship'];
$Course = $row['Course'];
$Semester = $row['Semester'];
$statusAllowance = $row['statusAllowance'];
?>
<tr>
<!-- Checkbox -->
<td><input type='checkbox' name='update[]' value='<?= $id ?>' ></td>
<td><p name="Name"><?php echo $row['Name']; ?></p></td>
<td><p name="Scholarship"><?php echo $row['Scholarship'] ?></p></td>
<td><p name="Course"><?php echo $row['Course'] ?></p></td>
<td><p name="Semester"><?php echo $row['Semester'] ?></p></td>
<td><p name='statusAllowance_<?= $id ?>'><?php echo $row['statusAllowance'] ?></td>
</tr>
<
?php
}
?>
</table>
</tbody>
<?php
if(isset($_SESSION['success']) && $_SESSION['success'] !='')
{
?>
<script type="text/javascript">
swal({
title: "<?php echo $_SESSION['success']; ?>",
icon: "<?php echo $_SESSION['status_code']; ?>",
button: "yissh",
});
</script>
<?php
unset($_SESSION['success']);
}
?>
This is my code on the edit part and this works, only the alert won't show up.
updataStatus.php
<?php
require_once "connection.php";
if(isset($_POST['but_update'])){
if(isset($_POST['update'])){
foreach($_POST['update'] as $id){
$statusAllowance = 'Received';
if($statusAllowance != '' ){
$updateUser = "UPDATE allowance SET statusAllowance='".$statusAllowance."' WHERE id=".$id;
$query_run = mysqli_query($conn,$updateUser);
if($query_run){
$_SESSION['success'] = "YOUR DATA UPDATED";
header('Location: tracking.php');
}else{
$_SESSION['success'] = "YOUR DATA IS NOT UPDATED";
header('Location: tracking.php');
}
}
}
}
}
?>
considering you have not implemented another function to call sweetalert; by default, it should be Swal.fire({}) not just swal({})
https://sweetalert2.github.io/

Using select option embeded in a table to dynamically change a user role to different roles via JQuery and AJAX

Im trying to dynamically allow the user to change a user role by using a select tag within a table which, when change triggers an event, record the changes in JQuery and send the changes to PHP via AJAX. From the image attached, the only select tag which fires an event is the one in the first row of the table shown. Any changes made to other rows does not fired an event as shown by one of the images with the console.log information. I am trying to allow whoever has the rights to change a specific user role by selecting the adajacent select option within the same table row which is send via AJAX to change the field in the database. I have posted this question before however Wesley Smith recommended I do a new post. Anyone please feel free to comment.
<?php
require_once('../../private/initialize.php');
require_login();
$admins = find_all_admins();
?>
<?php
if(isset($_SESSION['message']) )
{
echo "<div> </div><h5 style=\"color: #08ff00\">". $_SESSION['message'] ."</h5> </div>";
}
unset($_SESSION['message']);
//if(isset($SESSION['image_msg']))
//{
// echo "<div> </div><h5 style=\\" . $_SESSION['image_msg'] . "</#ffffff> </div>";
//}
?>
<form action="" method='post'>
<table class="table table-bordered table-hover">
<!-- <div id="bulkOptionContainer" class="col-xs-4">-->
<!---->
<!-- <select class="form-control" name="bulk_options" id="">-->
<!-- <option value="">Select Options</option>-->
<!-- <option value="published">Publish</option>-->
<!-- <option value="draft">Draft</option>-->
<!-- <option value="delete">Delete</option>-->
<!-- <option value="clone">Clone</option>-->
<!-- </select>-->
<!---->
<!-- </div>-->
<div class="col-xs-4" id="addnew" >
<!-- <input type="submit" name="submit" class="btn btn-success" value="Apply">-->
<a class="btn btn-primary" href="staff.php?source=add_staff">Add New</a>
</div>
<thead>
<tr>
<!-- <th><input id="selectAllBoxes" type="checkbox"></th>-->
<th>Image</th>
<th>First Name</th>
<th>Last Name</th>
<th>Email</th>
<th>Role</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<?php while ($all_admins = mysqli_fetch_assoc($admins)) { ?>
<tr>
<td><img src="<?php echo url_for('../images/staff/'.$all_admins['image'])?>" onerror="this.src='<?php echo url_for('../images/staff/profile.jpg') ?>'" style="border:1px solid #ddd;border-radius:2px; box-shadow: #4a5f63; height: 70px;width: 70px"></td>
<td><?php echo h($all_admins['first_name']) ?></td>
<td><?php echo h($all_admins['last_name']) ?></td>
<td><a class='btn btn-info' href="staff.php?source=show_staff&staff_id=<?php echo h($all_admins['id']) ?>"> <?php echo h($all_admins['email']) ?> </a></td>
<td>
<?php
$role = $all_admins['role'];
switch ($role){
case 'DE':
echo "Data Entry";
break;
case 'GU':
echo "General User";
break;
default:
echo "Administrator";
break;
}
?>
<span>
<select class="urole" name="role[]">
<option value="Admin" <?php echo ($role == 'Admin')?'selected':'' ?> >Admin</option>
<option value="DE" <?php echo ($role == 'DE')?'selected':'' ?> >Data Entry</option>
<option value="GU" <?php echo ($role == 'GU')?'selected':'' ?> >General User</option>
</select>
</span>
</td>
<td><a class='btn btn-info' href="staff.php?source=edit_staff&staff_id=<?php echo h($all_admins['id']) ?>">Edit</a></td>
<form method="post">
<input type="hidden" name="post_id" value="<?php //echo $post_id ?>">
<?php
echo '<td><input class="btn btn-danger" type="submit" name="delete" value="Delete"></td>';
?>
</form>
</tr>
<!---->
<!-- <td><input class='checkBoxes' type='checkbox' name='checkBoxArray[]' value='-->
<?php } //echo $post_id; ?><!--'></td>-->
<?php
mysqli_free_result($admins);
// echo "<td><a rel='$post_id' href='javascript:void(0)' class='delete_link'>Delete</a></td>";
// echo "<td><a onClick=\"javascript: return confirm('Are you sure you want to delete'); \" href='posts.php?delete={$post_id}'>Delete</a></td>";
// echo "<td><a href='posts.php?reset={$post_id}'>{$post_views_count}</a></td>";
// echo "</tr>";
//}
?>
</tbody>
</table>
</form>
<?php
//if (isset($_POST['delete'])) {
//
// $the_post_id = escape($_POST['post_id']);
//
// $query = "DELETE FROM posts WHERE post_id = {$the_post_id} ";
// $delete_query = mysqli_query($connection, $query);
// header("Location: /cms/admin/posts.php");
//
//
//}
//
//
//if (isset($_GET['reset'])) {
//
// $the_post_id = escape($_GET['reset']);
//
// $query = "UPDATE posts SET post_views_count = 0 WHERE post_id = $the_post_id ";
// $reset_query = mysqli_query($connection, $query);
// header("Location: posts.php");
//
//
//}
?>
<script>
$(document).ready(function ()
{
// $(".delete_link").on('click', function () {
//
//
// var id = $(this).attr("rel");
//
// var delete_url = "posts.php?delete=" + id + " ";
//
//
// $(".modal_delete_link").attr("href", delete_url);
//
//
// $("#myModal").modal('show');
//});
$('.urole').on('change',function (e){
e.preventDefault();
var val = $(".urole option:selected").val();
console.log(val);
console.log(e);
// $("#urole").on('click', function(){
// v
// });
//displayData(val);
});
$("#urole").ready(function (){
var val = $("#urole option:selected").val();
console.log(val);
//displayData(val);
});
});
function displayData(query){
$.ajax({
url:"enrolled_learners/enrol_learner_provider.php",
method:"post",
data:{query:query},
success:function (data)
{
//console.log(data);
$('#q-provider').html(data);
}
});
}
<?php
//if (isset($_SESSION['message'])) {
//
// unset($_SESSION['message']);
//
// }
?>
</script>
User Interface and Console log[enter image description here][1]
[User Interface][1]
Your selector selects all with the class urole, you just want to select the one that changed, since you're in the change handler for that element you can access it via the this keyword.
$('.urole').on('change',function (e){
e.preventDefault();
var val = this.value;
console.log(val);
console.log(e);
displayData(val);
});

Load php page on div with JavaScript

Trying to load php results (from a different page) into a div on same page on link clicked
I have tried following the answer in here
But this didn't work for me. Below is what i have tried
price.php
<div class="pricepop"></div>
<?php
$sql = $db->prepare("SELECT * FROM commodityprices");
$result = $sql->execute();
while ($row = $result->fetchArray(SQLITE3_ASSOC))
{
$id = $row['id'];
$_SESSION['id'] = $id;
$name = $row['name'];
$unit = $row['unit'];
$iprice = $row['iprice'];
$lprice = $row['lprice'];
$irate = $row['irate'];
$lrate = $row['lrate'];
$terms = $row['cterms'];
$asat = date('d/M/Y');
$market = $row['market'];
echo '<tr>
<td>'.$name.'</td>
<td>'.$unit.'</td>';
if ($irate == "Down")
{
echo '
<td style="background: #ef5a66; color: #fff"><i class="fa fa-caret-down"> </i> '.$iprice.'</td>';
}
else
{
echo '
<td style="background: #28bc88; color: #fff"><i class="fa fa-caret-up"> </i> '.$iprice.'</td>';
}
echo '<td>'.$terms.'</td>';
if ($lrate == "Down")
{
echo '
<td style="background: #ef5a66; color: #fff"><i class="fa fa-caret-down"> </i> '.$lprice.'</td>';
}
else
{
echo '
<td style="background: #28bc88; color: #fff"><i class="fa fa-caret-up"> </i> '.$lprice.'</td>';
}
echo '<td>'.$asat.'</td>
<td>'.$market.'</td>
<td><a class="comprice" href="pricedetails.php?id='.$id.'">View more</a>//Link to dispaly more results
</td>
</tr>';
}
pricedetails.php
<?php
$priceId = $_GET['id'];
$sql = $db->prepare("SELECT * FROM commodityprices WHERE id = ?");
$sql->bindParam(1, $priceId, SQLITE3_INTEGER);
$result = $sql->execute();
while ($row = $result->fetchArray(SQLITE3_ASSOC))
{
$id = $row['id'];
$name = $row['name'];
$iprice = $row['iprice'];
$lprice = $row['lprice'];
$lrate = $row['lrate'];
$terms = $row['cterms'];
$asat = date('d/M/Y');
$market = $row['market'];
$priceperbags = $row['priceperbags'];
echo '<tr>
<td>'.$name.'</td>';
echo '<td>'.$terms.'</td>';
if ($lrate == "Down")
{
echo '
<td style="background: #ef5a66; color: #fff"><i class="fa fa-caret-down"> </i> '.$lprice.'</td>';
}
else
{
echo '
<td style="background: #28bc88; color: #fff"><i class="fa fa-caret-up"> </i> '.$lprice.'</td>';
}
echo '<td>'.$asat.'</td>
<td>'.$market.'</td>
<td class="comprice">'.$priceperbags.'</td>
</tr>';
}
The JavaScript
$(document).ready(function() {
$(".comprice").on("click", function (e) {
e.preventDefault();
$(".pricepop").load("pricedetails.php");
});
});
When i click on the view more link in price.php the results in pricedeatils.php is supposed to display in the .pricepop div (which is in price.php page) but when i click currently the .pricepop is blank. Please how do i solve this issue? Thanks.
Your code isn't loading the correct url. Modified so id parameter is part of the url.
Use this js script instead.
$(document).ready(function() {
$(".comprice").on("click", function (e) {
e.preventDefault();
$(".pricepop").load($(this).attr('href'));
});
});

How to get correct price based on quantity in list using Cakephp2.x?

I have a listing page where I got item name,price,quantity.Now,I want if someone increase the quantity of item from list then price also increase according th actual price.Here is my file view_item.ctp
<?php
foreach($result as $k=>$v) { ?>
<tr class="hide_me_<?php echo $v['Inventory']['id']; ?> ">
<td><i class="fa fa-chevron-right"></i></td>
<td><?php echo $v['Inventory']['item_name']; ?></td>
<td class="text-center">
<span class="box-plush" id='plusbutton' onclick="itemQty(<?php echo
$v['Inventory']['id']; ?>,'incr')"><i class="fa fa-plus"></i></span>
<span class="box-dgt" id='att_<?php echo $v['Inventory']['id']; ?
>'>1</span>
<span class="box-minus" id='minusbutton' onclick="itemQty(<?php echo
$v['Inventory']['id']; ?>,'decr')"><i class="fa fa-minus"></i> </span>
</td>
<td class="text-center" id='price_<?php echo $v['Inventory']['id']; ?>'><?
php echo $v['Inventory']['item_price']; ?></td>
<td class="text-right"><?php echo $v['Inventory']['item_price']; ?></td>
<td class="text-center">
<a class="btn btn-danger btn-sm close-box" href="javascript:void(0)"
onclick="menuItem(<?php echo $v['Inventory']['id']; ?>)">
<i class="fa fa-times" ></i>
</a>
</td>
</tr>
<?php } ?>
<script type="text/javascript">
function menuItem(id){
$('.hide_me_'+id).hide();
}
function itemQty(id,action){
var qty = $('#att_'+id).text();
qty = parseInt(qty);
if(action=="incr"){
$qty1 = qty+1;
}else{
$qty1 = qty-1;
}
$('#att_'+id).text($qty1);
}
</script>
Replace onclick="itemQty(<?php echo $v['Inventory']['id']; ?>,'decr')" with data-row="<?php echo $v['Inventory']['id']; ?>"
add id="total_<?php echo $v['Inventory']['item_price']; ?>
to this line
<td class="text-right"><?php echo $v['Inventory']['item_price']; ?></td>
so it becomes <td class="text-right" id="total_<?php echo $v['Inventory']['item_price']; ?>"><?php echo $v['Inventory']['item_price']; ?></td>
modify your itemQty function to calculate price
function itemQty(id, action) {
let qty = $('#att_' + id).html();
qty = parseInt(qty);
if (action == "incr") {
qty++;
} else {
qty--;
}
$('#att_' + id).html(qty);
let price = parseFloat($('#price_' + id).html());
let total = price * qty;
$('#total_' + id).html(total.toFixed(2))
}
and then add this lines at the bottom
$(document).ready(function() {
$('#plusbutton').on('click', function() {
itemQty($(this).data('row'), 'incr')
})
$('#minusbutton').on('click', function() {
itemQty($(this).data('row'), 'decr')
})
})
demo here: https://jsfiddle.net/shahonseven/gn8sees8/

Wordpress button in wo-xml feed administration not working

Problem is in administration console of wordpress in plugin 'woocommerce xml feeds'. There is button to add parameter for category. This button do nothing when I click it.
I tried to contact the author of plugin, he only told me to check debug console, but there is nothing. He also told me that function of this button depends on jQuery.
This is the button element:
<span class="btn btn-danger btn-sm add-param" data-par="80">Přidat parametr</span>
The whole PHP file for context:
<?php
/**
*
* #package woo_xml_feeds
* #author Vladislav Musilek
* #license GPL-2.0+
* #link http://musilda.cz
* #copyright 2014 Vladislav Musilek
*
* Version 1.0.0
*
*/
if(isset($_POST['update'])){
//Save Heureka.sk Shipping values
$this->save_heureka_delivery($name = 'woo_heureka_delivery');
//Save Heureka.cz CPC value
$this->save_single_option('heureka-cpc','heureka-cpc');
/**
* Save Heureka category
*/
$heureka_assing_categories = get_option('woo_heureka_assing_categories');
if(empty($heureka_assing_categories)){ $heureka_assing_categories = array(); }
$heureka_excluded_categories = get_option( 'woo_heureka_excluded_categories');
if(empty($heureka_excluded_categories)){ $heureka_excluded_categories = array(); }
$heureka_categories_cpc = get_option( 'woo_heureka_categories_cpc');
if(empty($heureka_categories_cpc)){ $heureka_categories_cpc = array(); }
foreach($_POST['termid'] as $key => $item){
if(!empty($_POST['heurekaid'])){
if(!empty($_POST['heurekaid'][$key])){
$heureka_assing_categories[$_POST['termid'][$key]] = $_POST['heurekaid'][$key];
}else{
if(!empty($heureka_assing_categories[$_POST['termid'][$key]])){
unset($heureka_assing_categories[$_POST['termid'][$key]]);
}
}
}
if(!empty($_POST['excluded'][$key])){
$heureka_excluded_categories[$_POST['termid'][$key]] = $_POST['termid'][$key];
}else{
if(!empty($heureka_excluded_categories[$_POST['termid'][$key]])){
unset($heureka_excluded_categories[$_POST['termid'][$key]]);
}
}
if(!empty($_POST['termvar'][$key])){
$heureka_categories_cpc[$_POST['termid'][$key]] = $_POST['category_cpc'][$key];
}else{
if(!empty($heureka_categories_cpc[$_POST['termid'][$key]])){
unset($heureka_categories_cpc[$_POST['termid'][$key]]);
}
}
}
update_option( 'woo_heureka_assing_categories', $heureka_assing_categories );
update_option( 'woo_heureka_excluded_categories', $heureka_excluded_categories );
update_option( 'woo_heureka_categories_cpc', $heureka_categories_cpc );
//Parametry pro kategorie
$cat_params = get_option( 'woo_heureka_cat_params');
if(empty($cat_params)){ $cat_params = array(); }
foreach($_POST['termvar'] as $key => $item){
$cat_params[$item]['term_id'] = $item;
$cat_params[$item]['parametry'] = array();
if(!empty($_POST['nazev_parametru_'.$item])){
foreach($_POST['nazev_parametru_'.$item] as $lit => $var){
$cat_params[$item]['parametry'][$lit]['nazev_parametru'] = $_POST['nazev_parametru_'.$item][$lit];
$cat_params[$item]['parametry'][$lit]['hodnota_parametru'] = $_POST['hodnota_parametru_'.$item][$lit];
}
}
}
update_option( 'woo_heureka_cat_params', $cat_params );
if(isset($_GET['catoffset'])){
wp_redirect(admin_url().'admin.php?page=heureka-cz&catoffset='.$_GET['catoffset']);
}else{
wp_redirect(admin_url().'admin.php?page=heureka-cz');
}
}
$cat_params = get_option( 'woo_heureka_cat_params');
//Get heureka cz categories
$heureka_categories = get_option( 'woo_heureka_categories');
$heureka_assing_categories = get_option( 'woo_heureka_assing_categories');
$heureka_excluded_categories = get_option( 'woo_heureka_excluded_categories');
$heureka_categories_cpc = get_option( 'woo_heureka_categories_cpc');
$catTerms = get_terms('product_cat', array('hide_empty' => 0, 'orderby' => 'ASC'));
$cat_list = custom_taxonomy_walker('product_cat');
$use_select2 = get_option( 'woo_xml_feed_use_select2' );
/**
* Cat pagging
*
*/
$limit = 50;
if(isset($_GET['catoffset'])){
$catstart = (($_GET['catoffset'] * $limit) - $limit)+1;
$catend = $_GET['catoffset'] * $limit;
}else{
$catstart = 1;
$catend = $limit;
}
$i = 1;
$ii = 1;
?>
<div class="wrap">
<h2><?php echo esc_html( get_admin_page_title() ); ?></h2>
<form method="post" action="">
<?php
//Include Heureka CPC table
include('modules/heureka_cz_cpc.php');
//Include Heureka Shipping table
include('modules/heureka_cz_shipping.php');
//Display category setting paggination
echo tax_pagination($cat_list, 50);
?>
<!-- Heureka kategorie -->
<div class="t-col-12">
<div class="toret-box box-info">
<div class="box-header">
<h3 class="box-title"><?php _e('Přiřazení kategorií','woo-xml-feeds'); ?></h3>
</div>
<div class="box-body">
<p><?php _e('Zde můžete přiřadit všechny kategorie ve vašem obchodu, k jednotlivým kategoriím Heuréky. Pokud máte v eshopu větší množství kategorií, buďte prosím trpěliví, načtení může chvíli trvat. Po rozkliknutí výběru Heuréka kategorie, můžete do řádku zapsat počáteční písmena hledané kategorie a použít našeptávač.','woo-xml-feeds'); ?></p>
<p><?php _e('Pokud nechcete zobrazovat zboží z určité kategorie v XML feedu, zaškrtněte "Vyloučit kategorii".','woo-xml-feeds'); ?></p>
<table class="table-bordered">
<tr>
<th><?php _e('Vyloučit kategorii', 'woo-xml-feeds'); ?></th>
<th><?php _e('Kategorie obchodu', 'woo-xml-feeds'); ?></th>
<th><?php _e('Kategorie na Heuréce', 'woo-xml-feeds'); ?></th>
<th><?php _e('CPC kategorie', 'woo-xml-feeds'); ?></th>
</tr>
<?php
$catTerms = explode(',',$cat_list);
$aa = 0;
foreach($catTerms as $c_item) :
if(!empty($c_item) && $i >= $catstart){
if($i > $catend){ break; }
?>
<tr>
<td class="td_center"><input class="icheck_red" type="checkbox" name="excluded[<?php echo $aa; ?>]" <?php if(!empty($heureka_excluded_categories[$c_item])){ echo 'checked="checked"'; } ?> value="<?php echo $c_item; ?>" ></td>
<td>
<?php
$aa++;
$catTerm = get_term_by( 'id', $c_item, 'product_cat' );
if(!empty($catTerm->parent)){
$p_name = get_term_by( 'id', $catTerm->parent, 'product_cat' );
echo $p_name->name.' >> ';
}
?> <?php echo $catTerm->name; ?>
<input type="hidden" name="termid[]" value="<?php echo $catTerm->term_id; ?>" />
</td>
<td>
<?php
if(!empty($use_select2) && $use_select2 == 'no'){}else{
?>
<script>
jQuery(document).ready(function() { jQuery("#heureka<?php echo $i; ?>").select2(); });
</script>
<?php } ?>
<style>#s2id_heureka<?php echo $i; ?>{min-width:800px;}</style>
<select name="heurekaid[]" id="heureka<?php echo $i; ?>">
<option value="default"></option>
<?php
foreach($heureka_categories as $key => $item){
if(!empty($item['category_fullname'])){
?>
<option <?php if(!empty($heureka_assing_categories[$catTerm->term_id]) && $heureka_assing_categories[$catTerm->term_id]==$key){ echo 'selected="selected"'; }; ?>value="<?php echo $key; ?>"><?php echo $item['category_fullname']; ?></option>
<?php }
}
?>
</select>
</td>
<td><input type="text" name="category_cpc[]" value="<?php if(!empty($heureka_categories_cpc[$c_item])){ echo $heureka_categories_cpc[$c_item]; } ?>" style="width:40px;" /></td>
</tr>
<?php
}
$i++;
endforeach;
?>
</table>
</div>
</div>
</div>
<!-- Heureka kategorie parametry -->
<div class="t-col-12">
<div class="toret-box box-info">
<div class="box-header">
<h3 class="box-title"><?php _e('Vlastní parametry pro kategorie','woo-xml-feeds'); ?></h3>
</div>
<div class="box-body">
<table class="table-bordered">
<tr>
<th><?php _e('Kategorie eshop', 'woo-xml-feeds'); ?></th>
<th style="width:80%;"><?php _e('Vlastní parametry', 'woo-xml-feeds'); ?></th>
</tr>
<?php
$catTerms = explode(',',$cat_list);
foreach($catTerms as $c_item) :
if(!empty($c_item) && $ii >= $catstart){
if($ii > $catend){ break; }
?>
<tr>
<td>
<?php
$catTerm = get_term_by( 'id', $c_item, 'product_cat' );
if(!empty($catTerm->parent)){
$p_name = get_term_by( 'id', $catTerm->parent, 'product_cat' );
echo $p_name->name.' >> ';
}
?> <?php echo $catTerm->name; ?>
<input type="hidden" name="termvar[<?php echo $catTerm->term_id; ?>]" value="<?php echo $catTerm->term_id; ?>" />
</td>
<td class="category_params">
<?php
if(!empty($cat_params[$catTerm->term_id]['parametry'])){
foreach($cat_params[$catTerm->term_id]['parametry'] as $lit => $var){ ?>
<fieldset>
<input type="text" name="nazev_parametru_<?php echo $catTerm->term_id; ?>[]" placeholder="Název parametru" value="<?php echo $var['nazev_parametru']; ?>" />
<input type="text" name="hodnota_parametru_<?php echo $catTerm->term_id; ?>[]" placeholder="Hodnota parametru" value="<?php echo $var['hodnota_parametru']; ?>"/>
<span class="btn btn-danger btn-sm remove-param"><i class="fa fa-times"></i></span>
</fieldset>
<?php }
}
?>
<div class="clear"></div>
<span class="btn btn-danger btn-sm add-param"data-par="<?php echo $catTerm->term_id; ?>">Přidat parametr</span>
</td>
</tr>
<?php
}
$ii++;
endforeach;
?>
</table>
<input type="hidden" name="update" value="ok" />
<input type="submit" class="btn btn-lg btn-warning" value="<?php _e('Uložit nastavení','woo-xml-feeds'); ?>" />
</div>
</div>
</div>
</form>
</div>
I really tried to google it I found similar problems with some simple advice to switch to default theme or to put define('CONCATENATE_SCRIPTS', false); to wp-config.php. No luck with any of these.

Categories