How I Post This array in AJAX using AppendGrid plug in - php

I use AppendGrid as my plugin for table insert form containing header and detail.
Here is my code :
$('#tblAppendGrid').appendGrid({
initRows: 1,
columns: [
{ name: 'CodeNo', display: 'Code No', type: 'text', ctrlCss: { 'text-align': 'center' },ctrlAttr: { maxlength: '10' }},
{ name: 'CartonNo', display: 'Carton No', type: 'text', ctrlCss: {'text-align': 'center'},ctrlAttr: { maxlength: '10' }},
{ name: 'JawNo', display: 'Jaw No', type: 'text',ctrlCss: { 'text-align': 'center' },ctrlAttr: { maxlength: '10' }},
{ name: 'Time', display: 'Time', type: 'text', ctrlAttr: { maxlength: '10' },
ctrlCss: {'text-align': 'center' }, value: '<?php echo"$jam_ini";?>'},
{ name: 'wos', display: 'Weight Of Sample(67-72 g)',
type: 'text', ctrlAttr: { maxlength: 10 }, ctrlCss: { 'text-align': 'center' }},
{ name: 'odour', display: 'Odour/flavour&Taste (Normal)*',
type: 'select', ctrlOptions: {V: 'V',X: 'X'},ctrlCss: {'align': 'center' }},
{ name: 'ph', display: 'pH(6,0-6,4)', type: 'text', ctrlAttr: { maxlength: '10' }, ctrlCss: {'text-align': 'center' }},
{ name: 'et', display: 'Electrolit Test (Negative)', type: 'select', ctrlOptions: {N: 'N',P: 'P'}
,ctrlCss: {'align': 'center' }},
{ name: 'it', display: 'Ink. Test(Negative)**', type: 'select', ctrlOptions: {N: 'N',P: 'P','':''},
ctrlCss: {'align': 'center' }},
{ name: 'remark', display: 'Remark', type: 'text', ctrlAttr: { maxlength: '10' }, ctrlCss: {'text-align': 'center' }}
]
});
// Dummy: Handle save button clicked
$('#tombolsave').button().click(function () {
$("#status").html("Saving...");
$("#loading").show();
var HeaderID = $("#HeaderID").val();
var UserName = $("#UserName").val();
var date = $("#date").val();
var bop = $("#bop").val();
var pdate = $("#pdate").val();
var exdate = $("#exdate").val();
var line = $("#line").val();
var toi = $("#toi").val();
var data = $('#tblAppendGrid').appendGrid('getAllValue');
var count = $('#tblAppendGrid').appendGrid('getRowCount');
for (var i=0;i<=count;i++){
var CodeNo = data[i].CodeNo;
var CartonNo = data[i].CartonNo;
var JawNo = data[i].JawNo;
var Time = data[i].Time;
var wos = data[i].wos;
var odour = data[i].odour;
var ph = data[i].ph;
var et = data[i].et;
var it = data[i].it;
var remark = data[i].remark;
alert(it);
$.ajax({
type:'POST',
url: "aksi.php",
data: "op=save&HeaderID="+HeaderID+"&UserName="+UserName+"&date="+date+"&bop="+bop+
"&pdate"+pdate+"&exdate="+exdate+
"&line="+line+"&toi"+toi+"&i="+i+
"&CodeNo[]="+CodeNo+"&CartonNo[]"+CartonNo+"&JawNo[]="+JawNo+
"&Time[]="+Time+"&wos[]"+wos+"&odour[]="+odour+"&ph[]="+ph+"&et[]"+et+"&it[]="+it+
"&remark[]="+remark,
cache: false,
success: function(msg){
if(msg=="sukses"){
$("#status").html("Berhasil...");
$("#loading").hide();
document.location.reload();
}else{
$("#status").html("ERROR..");
}
}
});
}
});
});
My problem in AJAX POST, how I can post each detail value and how I use it in aksi.php.
Hope this can make sense.

in your script nothing wrong you just forget to add this "=" in a part like "&CartonNo[]"+CartonNo to "&CartonNo[]="+CartonNo
on aksi.php just make an array like
//script connect to database
for($i = 0; $i< $max; $i++){
//detail
$CartonNo = $_POST[CartonNo][$i];
....
//sql action
}

Related

How to update Chart.js based on dropdown list?

UPDATED
I have added a dropdown to my chart which allows the user to select among the available operator names.
I need your help so that when selecting an available operator name, the graphic is updated showing only the information of the selected operator.
From all my JSON response, for this example it should only show the information in a red box:
As you can see in the image, if I select the Luis operator, this graph should update and show me only the Luis operator (he has 2 work orders in finished state).
Below my report.js file which I use to make the graph.
getChartData () method:
I use ajax, basically I'm getting the data and loading my select with the names of the available operators.
renderChart () method:
 
I am passing it as a parameter "label and data" with these parameters I can make my graph also I am configuring some available options.
select.on ('change', function ():
here I do not understand how to tell my chart to update depending on the option selected, then I would have to call the renderChart method again to graph again with the selected data but it does not work, I do not know how to solve it, it is what I am trying.
report.js
function getChartData(user) {
$.ajax({
url: '/admin/reports/getChart/' + user,
type: 'GET',
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
dataType: 'json',
success: function (response) {
console.log(response);
var data = [];
var labels = [];
for (var i in response.orders) {
data.push(response.orders[i].orders_by_user);
labels.push(response.orders[i].name);
$("#operator").append('<option value='+response.orders[i].id+'>'+response.orders[i].name+'</option>');
}
renderChart(data, labels);
},
error: function (response) {
console.log(response);
}
});
}
function renderChart(data, labels) {
var ctx = document.getElementById("orders").getContext('2d');
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: labels,
datasets: [{
label: 'Terminadas',
data: data,
borderColor: 'rgba(75, 192, 192, 1)',
backgroundColor: "#229954",
borderWidth: 1,
yAxisID: 'Ordenes',
xAxisID: 'Operarios',
}]
},
options: {
scales: {
yAxes: [{
id: "Ordenes",
ticks: {
beginAtZero: true
},
scaleLabel: {
display: true,
labelString: 'Ordenes'
}
}],
xAxes: [{
id: "Operarios",
scaleLabel: {
display: true,
labelString: 'Operarios'
}
}],
},
title: {
display: true,
text: "Ordenes en estado terminado"
},
legend: {
display: true,
position: 'bottom',
labels: {
fontColor: "#17202A",
}
},
}
});
function updateChart() {
myChart.destroy();
myChart = new Chart(ctx, {
type: document.getElementById("operator").value,
data: data
});
};
}
getChartData();
$('#operator').select2({
placeholder: 'Selecciona un operario',
tags: false
});
var select = $('#operator');
var pElem = document.getElementById('p')
select.on('change', function() {
var item = $(this).val();
pElem.innerHTML = 'selectedValue: ' + item;
var data = {
labels: labels,
datasets: data
}
var ctx = document.getElementById("orders").getContext('2d');
var myChart = new Chart(ctx, {
type: 'line',
data: data
});
});
My select:
<select class="form-control" name="operator" id="operator">
<option></option>
</select>
I get lost trying to link the selected option and the information to show (update the graph). Could you please tell me how to solve this?
UPDATED 1
My select:
<select class="form-control" name="operator" id="operator">
<option></option>
</select>
Through ajax I load my select options:
for (var i in response.orders) {
order.push(response.orders[i].orders_by_user);
user.push(response.orders[i].name);
$("#operator").append('<option value='+response.orders[i].id+'>'+response.orders[i].name+'</option>');
}
renderChart(order, user);
With the answer you have given me, modify my report.js file exactly my function renderChart(order, user) and it is as follows:
function renderChart(order, user) {
var ctx = document.getElementById("orders").getContext('2d');
var myChart = new Chart(ctx, {
//code...
});
//my select
var selectOption = $('#operator');
selectOption.on('change', function() {
var option = $("#operator").val();
myChart.data.labels = option;
if (option == 'All') {
myChart.data.labels = user,
myChart.data.datasets[0].data = order;
} else {
myChart.data.labels = option;
myChart.data.datasets[0].data = order;
}
myChart.update();
});
}
The graph is updated incorrectly an error occurs you can see it in the image:
Obviously if I select the "All" option, it shows and graphs correctly, now if I select "jose" the following happens:
The graph does not respect the scale, I know that Jose has only 1 work order, and up to 2 on the scale.
On the x axis instead of showing me the name in this case "Jose" is showing me the selection id which in this case is 6.
The same happens with the option "Miguel".
Please help me correct this section:
var selectOption = $('#operator');
selectOption.on('change', function() {
var option = $("#operator").val();
myChart.data.labels = option;
if (option == 'All') {
myChart.data.labels = user,
myChart.data.datasets[0].data = order;
} else {
myChart.data.labels = option;
myChart.data.datasets[0].data = order;
}
myChart.update();
});
When the selected options changes, you must not destroy the chart. All you need to do is performing the following steps.
Change the data.labels
Change the data of the unique dataset
Update the chart itself
This is basically done as follows.
myChart.data.labels = <new labels>;
myChart.data.datasets[0].data = <new values>;
myChart.update();
The following example illustrates how this can be done in JavaScript.
orders = [
{ name: 'Luis', orders_by_user: '2' },
{ name: 'Jose', orders_by_user: '1' },
{ name: 'Miguel', orders_by_user: '3' }
];
const myChart = new Chart(document.getElementById('orders'), {
type: 'bar',
data: {
labels: orders.map(o => o.name),
datasets: [{
label: 'Terminadas',
data: orders.map(o => o.orders_by_user),
borderColor: 'rgba(75, 192, 192, 1)',
backgroundColor: "#229954",
borderWidth: 1,
yAxisID: 'Ordenes',
xAxisID: 'Operarios',
}]
},
options: {
scales: {
yAxes: [{
id: "Ordenes",
ticks: {
beginAtZero: true,
stepSize: 1
},
scaleLabel: {
display: true,
labelString: 'Ordenes'
}
}],
xAxes: [{
id: "Operarios",
scaleLabel: {
display: true,
labelString: 'Operarios'
}
}],
},
title: {
display: true,
text: "Ordenes en estado terminado"
},
legend: {
display: true,
position: 'bottom',
labels: {
fontColor: "#17202A",
}
},
}
});
orders.forEach(o => {
const opt = document.createElement('option');
opt.value = o.name;
opt.appendChild(document.createTextNode(o.name));
document.getElementById('operator').appendChild(opt);
});
function refreshChart(name) {
myChart.data.labels = [name];
if (name == 'All') {
myChart.data.labels = orders.map(o => o.name),
myChart.data.datasets[0].data = orders.map(o => o.orders_by_user);
} else {
myChart.data.labels = [name];
myChart.data.datasets[0].data = orders.find(o => o.name == name).orders_by_user;
}
myChart.update();
}
Operarios:
<select id="operator" onchange="refreshChart(this.value)">
<option>All</option>
</select>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.min.js"></script>
<canvas id="orders" height="90"></canvas>

How to show multiple highcharts on selection of few parameters and dynamically load JSON data using PHP page?

I have two parameters to load dynamic json data from mysql and visualise multiple line charts on page submit.
$.ajax({
url: 'get_pubmedid.php',
type: 'get',
data: {org: org, ptype: ptype, path: path,mirna: mirna},
dataType: 'json',
success:function(response) {
var len = response.length;
for( var i = 0; i<len; i++) {
pubmed = response[i]['name'];
cell=response[i]['cell'];
alert(cell+" "+pubmed+" "+len);
var cells=encodeURIComponent(cell);
var cname="charts"+(i+1);id=i+1;var pid=i+1;
var container = cname;
var func_name = cname;
func_name = function () {
Highcharts.chart(container, {
showhighcharts(org,ptype,path,mirna,cell,cells,pid,pubmed,cname,id);
}
}
func_name()
}
}
});
function showhighcharts(org,ptype,path,mirna,cell,cells,pid,pubmed,cname,id) {
$("#"+cname).html("Wait, Loading graph...");
var options = {
chart: {
type: 'line',
renderTo: cname
},
colors: ['#058DC7', '#50B432', '#ED561B', '#DDDF00', '#24CBE5', '#64E572', '#FF9655', '#FFF263', '#6AF9C4'],
credits: {
enabled: false
},
title: {
text: 'Temporal Viewer',
x: -20
},
xAxis: {categories:<?php //echo $_SESSION["cat"]; ?>,
offset:2,
title: {enabled: true,text: 'Time Point' }
},
tooltip: {
shared: true,
useHTML: true,
headerFormat: '<b>Time Point:{point.key}</b> <table style="width:200px;font-size:12px;font-weight:bold;">',
pointFormat: '<tr><td>Dosage:</td><td style="color: {series.color}">{series.name} </td></tr>' + '<tr><td>Fold Change:</td><td style="color: {series.color}">{point.y} </td></tr>',
footerFormat: '</table>',
enabled: true,
crosshairs: {
color: 'light gray',
dashStyle: 'longdash'
}
},
plotOptions: {
series: {
dashStyle: 'longdash'
},
line: {
dataLabels: {
enabled: true
},
enableMouseTracking: true
}
},
series: [{}]
};
$.ajax({
url: "jdatas.php?org="+org+"&ptype="+ptype+"&path="+path+"&mirna="+mirna+"&pid="+id+"&cell="+cell+"&pub="+pubmed,
data: 'show=impressions',
type:'get',
dataType: "json",
success: function(data){
var getSeries = data;
options.series = getSeries;
var chart1 = new Highcharts.Chart(options);
}
});
I want multiple graphs to be loaded on submit.
But its not showing any graph.

Laravel: DataTable Multiple checkboxes

Im fetching my data in my server side and I put checkbox.
I need some clarification, do I need to put checkbox here or it will be automatically added?
Controller
$result[] = array(
'#' => '<span style="font-size: 12px; color: gray">'.$counter++.'</span>',
'number' => '<p>'.$value->number.'</p>',
'vendor' => '<p>'.$vendor->name .'</p>',
'document_reference' => '<p>'.$value->document_reference.'</p>',
'date_needed' => '<p>'.$value->date_needed.'</p>',
'requesting_department' => '<p>'.$department->name.'</p>',
'amount' => '<p align="right">'.number_format($value->total_amount,2).'</p>',
'status' => '<p>'.$status.'</p>',
'approval_status' => '<p id="'.$value->id.'">'.$approval.'</p>',
'created_by' => '<p id="created_at'.$value->id.'">'.$user->name.'</p>',
'action' => '<i class="fa fa-eye"></i>',
'checkbox' => '<input type="checkbox" name="checkbox[]" value="'.$value->id.'">'
In my view page I used route to call this method. In here I have now my data.
My View
var table3 = $('#get-rfp-for-approval-table').DataTable({
'processing': true,
'serverSide': true,
ajax: {
url: '/requests/request-for-payment/getRFPforApproval',
dataSrc: ''
},
columns: [
{ data: '#' },
{ data: 'number' },
{ data: 'vendor' },
{ data: 'document_reference' },
{ data: 'date_needed' },
{ data: 'requesting_department' },
{ data: 'amount' },
{ data: 'status' },
{ data: 'created_by' },
{ data: 'approval_status' },
{ data: 'action' },
{ data: 'checkbox' },
],
columnDefs: [
{
targets: 11,
checkboxes: {
selectRow: true
}
}
],
select: {
style: 'multi'
},
order: [[1,'desc']]
});
Example I have 15 data, I checked data 5 and data 14. then I submit the form.
My form
if ( $('#approved-selected-form').length > 0 ) {
$('#approved-selected-form').submit(function(e){
var form = this;
var rows_selected = table3.column(0).checkboxes.selected();
// Iterate over all selected checkboxes
$.each(rows_selected, function(index, rowId){
// Create a hidden element
$(form).append(
$('<input>')
.attr('type', 'hidden')
.attr('name', 'checkbox[]')
.val(rowId)
);
});
var formData = $(this).serialize();
swal({
title: "Are you sure?",
text: "Transaction will be approved.",
icon: "warning",
buttons: true,
dangerMode: true,
})
.then((willSave) => {
if (willSave) {
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
})
$.ajax({
url: '/requests/request-for-payment/approvedTransaction',
type: "POST",
data: formData,
beforeSend: function() {
var span = document.createElement("span");
span.innerHTML = '<span class="loading-animation">LOADING...</span>';
swal({
content: span,
icon: "warning",
buttons: false,
closeOnClickOutside: false
});
$('.request-for-payment-finish').attr('disabled', 'disabled');
},
success: function(response) {
if (response != '') {
$('#get-request-for-payment-table').DataTable().destroy();
getRequestForPaymentTable();
$('#add-request-for-payment-form').trigger("reset");
swal("Transaction has been saved!", {
icon: "success",
});
setTimeout(
function()
{
window.location.href = "/requests/request-for-payment?id="+response+"#view-request-for-payment-modal";
}, 1500);
}
},
complete: function() {
$('.request-for-payment-finish').removeAttr('disabled');
}
});
} else {
swal("Save Aborted");
}
});
e.preventDefault();
return false;
})
}
NOTE: I tried to dd it in my controller it gives me this
array:1 [
"get-rfp-for-approval-table_length" => "10"
]
I also noticed that in my th, I dont have checkbox(when I clicked this, everything will be checked). Im using this as a guide. https://jsfiddle.net/snqw56dw/3182/.
Question: How can I get those values in my controller?
You should be returning ID in your controller.
$result[] = array(
// ... skipped ...
'checkbox' => $value->id
);
Also since checkbox in column with index 11, you should be using that index when retrieving the data.
var rows_selected = table3.column(11).checkboxes.selected();
On the side note, I see that you're using server-side processing mode ('serverSide': true). Make sure your controller returns proper response.

Extract text from input extjs and send it to php

I have a login with username and password, and a button with login. I want to send data from username and password to server-side PHP.
Ext.require([
'Ext.form.Panel',
'Ext.layout.container.Anchor'
]);
var log = Ext.onReady(function () {
Ext.create('Ext.form.Panel', {
renderTo: 'login',
title: 'Login section',
bodyPadding: '10 10 0',
width: 300,
fieldDefaults: {
labelAlign: 'top',
msgTarget: 'side'
},
defaults: {
border: false,
xtype: 'panel',
flex: 1,
layout: 'anchor'
},
layout: 'hbox',
items: [{
items: [{
xtype: 'textfield',
fieldLabel: 'User Name',
anchor: '-5',
name: 'first',
id: 'userName'
}, {
xtype: 'textfield',
fieldLabel: 'Password',
anchor: '-5',
name: 'password',
inputType: 'password',
id: 'password'
}]
}
],
buttons: ['->', {
text: 'Login',
name: 'submit',
/*listeners: {
tap: function () {
var form = Ext.getCmp('userName');
//var values = form.getValues();
Ext.Ajax.request({
url: 'index.php',
params: form,
success: function (response) {
var text = response.responseText;
Ext.Msg.alert('asfasfaf', text);
},
failure: function (response) {
Ext.Msg.alert('Error', 'Error while submitting the form');
console.log(response.responseText);
}
});
}
}*/
/* handler: function () {
Ext.Ajax.request({
url: 'index.php',
method: 'POST',
params: Ext.getCmp('userName').getValue(),
success: function (response) {
Ext.Msg.alert('success ' + Ext.getCmp('userName').getValue());
},
failure: function (response) {
Ext.Msg.alert('server-side failure with status code ' + response.status);
}
});
}*/
},
{
text: 'Register?'
}]
});
});
I see that you have already tried to extract values and send request to php. May be this structure will help you. But you have to be sure that your php url accepts parameters with names 'param1' and 'param2' (or whatever your php accepts:) )
{
xtype : 'button',
text : "Submit"
formBind : true,
handler : function() {
var userName = this.up('form').down('#userName');
var password = this.up('form').down('#password');
Ext.Ajax.request({
url: url, // your php url
method: 'POST',
params: {param1: userName, param2:password },
disableCaching: false,
success: function(response, opts)
{
var text = response.responseText; // for debugging print text and decodedText
var decodedText = Ext.decode(text);
if(decodedText.success)
{
}
}
failure: function()
{
}
});
}
}
Ext.getCmp('userName').getValue();
You can use the Ext Form's submit method from within your button handler, e.g.:
// ....
buttons: [{
text: 'Submit!',
handler: function(btn) {
btn.up('form').getForm().submit({
url: 'mybackend.php',
success: function(ret) {},
failure: function(ret) {},
});
}
}],
// .....

jquery not working in html

I'm trying to do a jquery ajax tutorial but I'm not able to get it to work.
$(document).ready(function () {
//var theme = getDemoTheme();
var url = "http://localhost/schoollife/services/getchapters.php?a=showdata";
// prepare the data
var source =
{
datatype: "json",
datafields: [
{ name: 'curriculam_type', type: 'string' },
{ name: 'class_type', type: 'string' },
{ name: 'subject_type', type: 'int' },
{ name: 'chapter_name', type: 'string' },
{ name: 'chapter_number', type: 'int' },
{ name: 'author_name', type: 'string' },
{ name: 'reviewer_name', type: 'int' }
],
//id: 'id',
url: url
};
var dataAdapter = new $.jqx.dataAdapter(source);
$("#jqxgrid").jqxGrid(
{
width: 940,
source: dataAdapter,
//theme: theme,
columnsresize: true,
columns: [
{ text: 'Curriculum', datafield: 'curriculam_type', width: 100 },
{ text: 'Class', datafield: 'class_type', width: 100 },
{ text: 'Subjects', datafield: 'subject_type', width: 100 },
{ text: 'Chapter', datafield: 'chapter_name', width: 160 },
{ text: 'Chapter Number', datafield: 'chapter_number', cellsalign: 'center',width: 60},
{ text: 'Content Author', datafield: 'author_name'},
{ text: 'Content Reviewer', datafield: 'reviewer_name'},
{ text: 'Edit', datafield: 'Edit', width: 60, cellsrenderer: function () {
return '<div style="width:100%"><img src="../images/edit.png" style="margin-left: 25%"/></div>';
},
},
{ text: 'Delete', datafield: 'delete', width: 60, cellsrenderer:function () {
return "<div style='width:100%'><a href='javascript:void(0)' class='**delbutton**'><img src='../Images/delete.png' style='margin-left:25%'/></a></div>";
},
},
]
});
$(document).ready(function() {
$(".**delbutton**").click(function(){
alert('sdsdsd');
alert('Are You sure you want to delete!');
evt.preventDefault();
var id=this.href;
var url='http://localhost/schoollife/services/getchapters.php?a=deletechapter&chapter_id='+data[i].id;
$.messager.confirm('Confirm','Are you sure you want to delete record?');
$.ajax({
cache:false,
dataType:'json',
url:'http://localhost/schoollife/services/getchapters.php?a=deletechapter&chapter_id='+data[i].id,
async:false,
success:function(data){
alert(data);
}
})
});
});
});
If I do the same in a .js file I wouldn't have any problem. What am I missing here?
Thanks
Well, what about <script> tag:
<script>
//js code here
</script>
You need of course to place it after including jquery.
you have to close }); first document on load function . and consider about open bracket and close bracket

Categories