I'm having a little bit trouble about sending a database data to a client side table. I'am using fancy grid.
Client Side
$.ajax({
url:'function.php?what=listofbookings',
type:'post',
data:{user:user},
success: function(data) {
var clients = data;
}
});
});
$("#jsGrid").jsGrid({
width: "100%",
height: "400px",
inserting: true,
editing: true,
sorting: true,
paging: true,
data: clients,
fields: [
{ name: "people", type: "text", width: 150, validate: "required" },
{ name: "email", type: "number", width: 50 }
]
});
And here is the PHP Code
if(isset($_GET['what'])){
if($_GET['what'] === 'listofbookings'){
$selit = "SELECT * FROM dbdbdb_booking";
$queryit = mysqli_query($conn,$selit);
$arr = array();
while($row = mysqli_fetch_assoc($queryit)){
$arr[] = $row;
}
echo json_encode($arr);
}
}
For some reason the var client is not defined and the data is not passing to clients.
Any thoughts ?
You need to initialize jsGrid inside your AJAX's success :
$.ajax({
url:'function.php?what=listofbookings',
type:'post',
data:{user:user},
success: function(data) {
var clients = data;
$("#jsGrid").jsGrid({
width: "100%",
height: "400px",
inserting: true,
editing: true,
sorting: true,
paging: true,
data: clients,
fields: [
{ name: "people", type: "text", width: 150, validate: "required" },
{ name: "email", type: "number", width: 50 }
]
});
}
});
Related
I'm using this code to create a simple CRUD using Jsgrid and php, but the page isn't loading when i change the type field to date. I watched almost the entire youtube and I didn't find anything about.
I dont even know what to do
Can somebody help me?
index.php:
<body>
<div class="container">
<br />
<div class="table-responsive">
<h3 align="center">Inline Table Insert Update Delete in PHP using jsGrid</h3><br />
<div id="grid_table"></div>
</div>
</div>
<script type="text/javascript" src="js.js"></script>
</body>
js.js
var db = {
loadData: function(filter){
return $.ajax({
type: "GET",
url: "fetch_data.php",
data: filter
});
},
insertItem: function(item){
return $.ajax({
type: "POST",
url: "fetch_data.php",
data: item
});
},
updateItem: function(item){
return $.ajax({
type: "PUT",
url: "fetch_data.php",
data: item
});
},
deleteItem: function(item){
return $.ajax({
type: "DELETE",
url: "fetch_data.php",
data: item
});
}
};
var MyDateField = function (config) {
jsGrid.Field.call(this, config);
};
MyDateField.prototype = new jsGrid.Field({
sorter: function (date1, date2) {
return new Date(date1) - new Date(date2);
},
itemTemplate: function (value) {
return new Date(value).toDateString();
},
insertTemplate: function (value) {
return this._insertPicker = $("<input class='date-picker'>").datetimepicker();
},
editTemplate: function (value) {
return this._editPicker = $("<input class='date-picker'>").datetimepicker();
},
insertValue: function () {
return this._insertPicker.data("DateTimePicker").useCurrent();
},
editValue: function () {
return this._editPicker.data("DateTimePicker").useCurrent();
}
});
jsGrid.fields.date = MyDateField;
$('#grid_table').jsGrid({
width: "100%",
height: "600px",
filtering: true,
inserting:true,
editing: true,
sorting: true,
paging: true,
autoload: true,
pageSize: 10,
pageButtonCount: 9,
deleteConfirm: "Do you really want to delete data?",
controller: db,
fields: [
{
name: "id",
type: "hidden",
css: 'hide'
},
{
title:"Load Number",
name: "loadnumber",
type: "text",
width: 150,
validate: "required"
},
{
title:"Broker MC",
name: "brokermc",
type: "text",
width: 150,
validate: "required"
},
{
title:"Broker",
name: "brok3r",
type: "text",
width: 50,
validate: function(value)
{
if(value > 0)
{
return true;
}
}
},
{
title:"Driver",
name: "driver",
type: "text",
width: 150,
validate: "required"
},
{
title:"Load Date",
name: "loaddate",
type: "date"
},
{
type: "control"
}
]
});
i tried to rename to "MyDateField", the page loads but the item field disappears, how can i fix it?
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.
My aim is to add select box in my grid system, and I get success to add select box following the below code.
But after adding select box my other data is not showing up, when I do search from my dropdown filter it is showing data.
$("#jsGrid").jsGrid({
height: 480,
width: "100%",
filtering: true,
editing: false,
sorting: true,
paging: true,
autoload: true,
clearFilterButton: true,
pageSize: 10,
pageButtonCount: 10,
controller: {
loadData: function(filter) {
criteria = filter;
var data = $.Deferred();
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
url: "myURL",
dataType: "json"
}).done(function(response) {
var res = [];
if (criteria.component !== "") {
response.forEach(function(element) {
if (element.component.indexOf(criteria.component) > -1) {
res.push(element);
response = res;
}
}, this);
} else res = response;
if (criteria.titleLong !== "") {
res = [];
response.forEach(function(element) {
if (element.titleLong.indexOf(criteria.titleLong) > -1)
res.push(element);
}, this);
} else res = response;
data.resolve(res);
});
return data.promise();
}
},
fields: [{
name: "component",
type: "textarea",
width: 150
}, {
name: "Id",
type: "text",
width: 50
}, {
name: "titleLong",
type: "select",
align: "center", // center text alignment
autosearch: true, // triggers searching when the user changes the selected item in the filter
items: ["", "A", "B", "C"], // an array of items for select
valueField: "", // name of property of item to be used as value
textField: "", // name of property of item to be used as displaying value
selectedIndex: -1, // index of selected item by default
valueType: "string", // the data type of the value
readOnly: false, // a boolean defines whether select is readonly (added in v1.4)
}, {
name: "unit",
type: "textarea",
width: 150
}, {
name: "descr",
type: "textarea",
width: 150
}]
});
So My aim is to display all the data on Page load and if someone perform search using select filter show it related data of the performed search.
Possibly, removing "," from "readOnly: false," in third field definition can help.
Please anyone help me in fixing this. I am trying add dynamic column names and column models information from the php script named simple8.php and the data is obtaining from the simple7.php.
<script type="text/javascript">
jQuery(function($) {
var seq= $('#sim').text();
var seq= seq.replace(/[\“\”\″]/ig,'\"');
var seq = jQuery.trim(seq);
var title = $('#title_for_table').text();
var title = jQuery.trim(title);
$.ajax({
url:"simple8.php"+seq,
type: "POST",
data: "",
dataType: "json",
success: function (data) {
var ColN = data.colNames;
var ColM = data.colModel;
jQuery("#tableid").jqGrid({
url: "simple7.php"+seq,
datatype: "jsonstring",
mtype: "POST",
colNames: ColN,
colModel: ColM,
pager: '#pager',
rowNum:50,
rowList:[25,50,75,100],
sortname: 'r1',
sortorder: "asc",
viewrecords: true,
gridview: true,
height: '100%',
width: '100%',
caption:title+" Search Results",
loadComplete: function(reload) {
jQuery("#tableid").trigger("reloadGrid");
},
});
jQuery("#tableid").jqGrid('navGrid','#pager',{add:false,edit:false,del:false});
jQuery("#tableid").jqGrid('navButtonAdd','#pager',{caption: "Export",onClickButton: function () { //exportExcel($(this));
ExportJQGridDataToExcel($(this),'file1.xls');
},position:"last"
});
},
error: function () {
alert("Error with AJAX callback");
}
});
});
</script>
the output of simple8.php is:
{"colNames":"['col','r1', 'r2', 'r3', 'r4', 'r5', 'r6', 'r7', 'r8', 'r9', 'r10', 'r11']","colModel":"[{name:'col', index:'col', width:120},{name:'r1', index:'r1', width:120},{name:'r2', index:'r2', width:120},{name:'r3', index:'r3', width:120},{name:'r4', index:'r4', width:120},{name:'r5', index:'r5', width:120},{name:'r6', index:'r6', width:120},{name:'r7', index:'r7', width:120},{name:'r8', index:'r8', width:120},{name:'r9', index:'r9', width:120},{name:'r10', index:'r10', width:120},{name:'r11', index:'r11', width:120}]"}
and simple7.php gives:
{"total":1,"page":1,"records":4,"rows":[{"id":null,"cell":["Chaffa","R","R","C","A","C","A","A","T","T","G","G"]},{"id":null,"cell":["CSG8962","R","R","Y","A","C","A","A","T","T","G","S"]},{"id":null,"cell":["DCP92_3","G","A","C","M","C","A","A","T","W","G","G"]},{"id":null,"cell":["DigVijay","R","A","C","A","C","A","A","T","T","G","S"]}]}
Please let me know where i am wrong.
The value of colNames is a string instead of array of items. The same one can say about colModel. You should change the data returned from the server to use only " instead of ' and then use colNames: $.parseJSON(ColN) and colModel: $.parseJSON(ColM) instead of colNames: ColN, colModel: ColM. Without replacing ' with " you will have error in parsing of JSON in $.parseJSON.
I want to display Text for my ForigenKey columns instead of numeric values. There are a lot of examples to retrieve TextMember by comparing ID but they are not working in my case. I just started to use Kendo ui so dont know much about it
Here is the code :
$(document).ready(function () {
dataSource1 = new kendo.data.DataSource({
transport: {
read: {
url: "Data/AttendanceCode/GridSelect.php",
dataType: "json",
},
update: {
url: "Data/AttendanceCode/GridUpdate.php",
dataType: "json",
type:"GET"
},
destroy: {
url: "Data/AttendanceCode/GridDelete.php",
dataType: "json",
type:"POST"
},
create: {
url: "Data/AttendanceCode/GridInsert.php",
dataType: "json",
type:"POST"
},
},
schema: {
data: "data",
model: {
id: "AttendenceID",
fields: {
AttendenceID : { editable: false, nullable: true },
TeacherID: { field: "TeacherID", defaultValue: "EIIT0002" },
}
}
},
});
$("#grid").kendoGrid({
dataSource: dataSource1,
pageSize: 10,
pageable: {
refresh: true,
pageSizes: true
},
editable:{ mode : "popup" },
height: 400,
filterable: true,
columnMenu: true,
sortable: true,
reorderable: true,
resizable: true,
toolbar: ["create"],
columns: [
{ field:"AttendenceID", title: "Attendence ID", width:"130px" },
{ field: "TeacherID", title:"Teacher", width: "100px" , editor: TeacherDropDownEditor, template: "#=getTeacherName(TeacherID)#" },
{ command: ["edit", "destroy"], title: "Action", width: "210px" }],
});
});
Teacher DropDown DataSource
teacher = new kendo.data.DataSource({
transport: {
read: {
url : "Data/Teacher.php",
dataType: "json" }
},
schema: {
data : "Teacher"
}
});
// Teacher Editor
function TeacherDropDownEditor(container, options) {
$('<input data-bind="value:' + options.field + '"/>')
.appendTo(container)
.kendoDropDownList({
dataTextField: "TeacherName",
dataValueField: "Service_NO",
dataSource: teacher
});
}
Different approaches i found and tried to Get Teacher Name
1 -
function getTeacherName(value) {
var text = "";
$.each(teacher, function () {
if (this.Service_NO == value) {
text = this.Name;
return false;
}
});
return text;
}
2 -
function getTeacherName(teacherID) {
for (var idx = 0, length = teacher.length; idx < length; idx++)
{
if (teacher[idx].Service_NO === teacherID)
{t = teacher[idx].Name;}
}
return t;
}
3 -
function getTeacherName(teacherID) {
$.each(teacher, function(key, val) {
if(val.Service_NO == tID){
t = val.Name;
}
});
return t;
}
It seems like dataSource (teacher) is not having any value.
PHP code is working perfectly.
Please Help if you have any idea whats wrong with my code.
Thanks !!
You are right, teacher DataSource does not have any data because you are defining how to get the data (that's what you do with the DataSource) but you are not reading it.
Add:
teacher.read();
for manually forcing the data read.
NOTE: This is something that happens magically when you have a Grid, ListView,... because these widget do it for you but this time, for displaying your grid you need to read it in advance since it is invoked from a JavaScript function (KendoUI grid code doesn't know anything about what you have in the function getTeacherName other than the name).
you should config your field:
{ field: "nu_status", title: 'Status', values: [ { text: "Active", value: 1 }, { text: "Inactive", value: 0 }]},