I'm having an issue with Jqgrid, I've got two grids on a single page and onclick on a row of the first grid needs to reload the second grid.
I'm 100% sure the second grid is configured correctly is if I manually pass a hard coded id it populates correctly.
Just the reload function is not working. Please could someone assist. Below is the jquery code for both grids
$(document).ready(function() {
jQuery("#list2").jqGrid({
url:'classes/ListServices.php',
datatype: "json",
mtype: 'POST',
colNames: ['Id','Description', 'Details', 'Cost in (R)'],
colModel: [
{name:'Id',index:'Id', align:"center", width:30},
{name:'Description',index:'Description', align:"center"},
{name:'Details',index:'Details', align:"left"},
{name:'Cost',index:'Cost',align:"center",width:30,formatter:'currency'},
],
width: 780,
height: 100,
rowNum:18,
pager: '#pager1',
loadonce: true,
sortname: 'id',
viewrecords: true,
sortorder: "asc",
caption:"Services List",
multiselect: false,
onSelectRow: function(ids) {
if(ids == null) {
ids=0;
if(jQuery("#list3").jqGrid('getGridParam','records') >0 ) {
jQuery("#list3").jqGrid('setGridParam',
{url:"subgrid.php?q=1&id="+ids,page:1});
jQuery("#list3").jqGrid.trigger('reloadGrid');
}
}
else {
jQuery("#list3").jqGrid('setGridParam',
{url:"subgrid.php?q=1&id="+ids,page:1});
jQuery("#list3").jqGrid.trigger('reloadGrid');
}
}
});
jQuery("#list2").jqGrid('navGrid','#pager2',
{edit:false,add:false,del:false,multipleSearch:true});
jQuery("#list2").jqGrid('filterToolbar',
{stringResult: true,searchOnEnter : false});
jQuery("#list3").jqGrid({
url:'classes/ListServicesDetails.php?Id=2',
datatype: "json",
mtype: 'POST',
colNames: ['Id','ServiceId', 'Description', 'Details', 'Cost in (R)'],
colModel: [
{name:'Id',index:'Id', align:"center", width:30},
{name:'ServiceId',index:'ServiceId', align:"center", width:30},
{name:'Description',index:'Description', align:"center"},
{name:'Details',index:'Details', align:"left"},
{name:'Cost',index:'Cost',align:"center",width:30,formatter:'currency'},
],
width: 780,
height: 200,
rowNum:18,
pager: '#pager2',
loadonce: true,
sortname: 'id',
viewrecords: true,
sortorder: "asc",
caption:"Services Details List",
multiselect: false,
onSelectRow: function(id) {
alert(id);
}
});
jQuery("#list3").jqGrid('navGrid','#pager2',
{edit:false,add:false,del:false,multipleSearch:true});
});
Please if someone could assist me ...
Thanks
Both jqGrids has parameters loadonce: true. It means that after the first loading the datatype of the grids will be changed from "json" to "local". To reload the second grid you should reset the datatype parameter to "json" together with url and page parameters.
Related
I'm using a PHP page to update the data when I edit them in the jqGrid (using the parameter "editurl").
$("#campionati").jqGrid({
url: "dbread.php",
datatype: "json",
mtype: "GET",
colNames: ["ID", "Nome", "Descrizione", "URL"],
colModel: [
{name: "id", width: 16, align: 'center'},
{name: "nome", width: 90, align: 'right', editable: true},
{name: "descrizione", width: 80, editable: true},
{name: "url", width: 600, editable: true, formatter: 'link', formatoptions: {target: '_blank'}}
],
editurl: "dbwrite.php?action=updateCampionati",
pager: "#pager",
...
It works.
My question is: what's kind of data that my PHP page has to return to tell to jqGrid if the update has been successful or not?
<php
...
echo 0;
or
<php
...
echo json_encode(array("result" => "OK"));
It's important the HTTP status code of the server response. You code seems to return the status code 200 OK. So the response will be interpreted as successful. To return information about the error one can use http_response_code for example.
$(document).ready(function() {
$("#myDataList").jqGrid({
url: "<?= base_url(); ?>getmydata/getCategory",
datatype: "json",
autowidth: true,
mtype: "GET",
colNames: ["Category", "Description", ""],
colModel: [
{name: "c_category", editable: true, width: 1},
{name: "c_description", editable: true, width: 4, edittype: 'textarea'},
{name: "categoryid", key: true, editable: true, hidden: true, editrules: {edithidden: false}}
],
pager: "#myDataListPager",
rowNum: 10,
rowList: [10, 20, 30],
sortname: "c_category",
sortorder: "asc",
height: 'auto',
viewrecords: true,
gridview: true,
caption: "",
editurl: "<?= base_url(); ?>getmydata/c_action"
});
jQuery("#myDataList").jqGrid('navGrid', '#myDataListPager', {add: true, edit: true, del: true, search: true},
{closeAfterEdit: true}, {closeAfterAdd: true}, {
beforeShowForm: function($form) {
$("td.delmsg", $form[0]).html("Do you want to delete the row with <b>id=" +
$("#myDataList").jqGrid('getGridParam', 'selrow') + "</b>?");
},
afterSubmit: function(response) {
response = $.parseJSON(response.responseText);
alert(response.error);
if (response.error == 0) {
$.openDialog("info", "Successfully deleted ");
} else {
showDialog($('#Dialog'), response.msg, "An error occured");
}
}}
);
});
Above is my grid code, When I click delete the id is the rowid instead of the categoryid, how can I set the id to categoryid instead of row id. I would like to show a dialog message if the response.error is true. When I alert the response.error, I can get the correct result, but I don't know how to call the dialog to display.
http://mymoney.webege.com/getmydata/getCategory?_search=false&nd=1408865724728&rows=10&page=1&sidx=c_category&sord=asc <-- this is the URL I get the json data.
Above is my return json, and I check when click the delete the id is the row id in sequence.
You use key: true for the column "categoryid". So the values of rowid and categoryid have to be identical. You should post an example of testdata which can be used to reproduce the problem or you can debug the code yourself to understand why rowid and categoryid are different in your case.
You second problem with afterSubmit is easy to solve. You should don't show any dialogs inside of afterSubmit. Instead of that you should just return the required information in the correct format. afterSubmit of form editing have to return array of up to 3 items. In case of Delete operation if could be up to 2 items. If no error take place then you should return [true]. In case of error you should return [false, "error description"]. If your case it would be something like below
afterSubmit: function (response) {
var data = $.parseJSON(response.responseText);
return (data != null && data.error !== 0) ? [false, data.msg] : [true];
}
I am a newbie to jqgrid and I am using jqgrid for displaying data along with codeigniter.
these are my grids:
grid 1
Student Table
<table id="list"></table>
<div id="pager"></div>
grid 2
Tutor Table
<table id="list1"></table>
<div id="pager1"></div>
I am loading a second grid when a user is double clicking on a row of the first grid.
My jqgrid code is:
<script type="text/javascript">
$(document).ready(function (){
var lastSel;
jQuery("#list").jqGrid({
url:'<?php echo $base_url.'index.php/demo/loadData'?>', //another controller function for generating data
mtype : "post", //Ajax request type. It also could be GET
datatype: "json", //supported formats XML, JSON or Arrray
colNames:['Name','Email','Passport','Phone','Fax','Address','Note'], //Grid column headings
colModel:[
{name:'name',index:'name', width:100, align:"left",editable:false},
{name:'email',index:'email', width:150, align:"left",editable:false},
{name:'passport',index:'passport', width:100, align:"right",editable:true},
{name:'phone',index:'phone', width:100, align:"right",editable:false},
{name:'fax',index:'fax', width:100, align:"right",editable:true},
{name:'address',index:'address', width:100, align:"right",editable:true},
{name:'note',index:'note',width:100,align:"right",editable:true},
],
rowNum:10,
width: 750,
//height: 300,
rowList:[10,20,30],
pager: '#pager',
sortname: 'id',
viewrecords: true,
rownumbers: true,
gridview: true,
caption:"List Of Students",
ondblClickRow:function(id){
if(id && id!==lastSel){
jQuery('this').restoreRow(lastSel);
lastSel=id;
}
// alert(id);
jQuery("#list1").jqGrid({
url:"<?php echo $base_url.'index.php/demo/load_tutor_data/'?>"+$('#'+id).children("td[aria-describedby='list_passport']").html(), //another controller function for generating data
mtype : "post", //Ajax request type. It also could be GET
datatype: "json", //supported formats XML, JSON or Arrray
colNames:['Name','Email','Passport','Phone','Fax','Address','Note','Assign',''], //Grid column headings
colModel:[
{name:'name',index:'name', width:100, align:"left",editable:false},
{name:'email',index:'email', width:150, align:"left",editable:false},
{name:'passport',index:'passport', width:100, align:"right",editable:true},
{name:'phone',index:'phone', width:100, align:"right",editable:false},
{name:'fax',index:'fax', width:100, align:"right",editable:true},
{name:'address',index:'address', width:100, align:"right",editable:true},
{name:'note',index:'note',width:100,align:"right",editable:true},
{name: 'checkbox', index: 'checkbox', align:"center",editable: true,
edittype: 'checkbox', editoptions: { value: "True:False" ,defaultvalue:"False" },
formatter: "checkbox", formatoptions: { disabled: false} },
{name: 'myac', width:80, fixed:true, sortable:false, resize:false, formatter:'actions',
formatoptions:{keys:true}},
],
rowNum:10,
width: 750,
//height: 300,
rowList:[10,20,30],
pager: '#pager1',
sortname: 'id',
viewrecords: true,
rownumbers: true,
gridview: true,
caption:"List Of Tutors",
onSelectRow:function(id){
alert("Assign Here");
},
onCellSelect:function(rowid, iCol, cellcontent, e){
if(iCol==8)
alert("make submit");
},
editurl:"<?php echo $base_url.'index.php/demo/load_tutor_data'?>"
}).navGrid('#pager1',{edit:false,add:false,del:false});
$("#admintask").show();
},
editurl:"<?php echo $base_url.'index.php/demo/loadData'?>"
}).navGrid('#pager',{edit:false,add:false,del:false});
$("tr").click(function(){
alert("test");
});
});
$("#bsdata").click(function(){
jQuery("#list").jqGrid('searchGrid',
{sopt:['cn','bw','eq','ne','lt','gt','ew']}
);
});
$("#bedata").click(function(){
var gr = jQuery("#list").jqGrid('getGridParam','selrow');
if( gr != null ) jQuery("#list").jqGrid('editGridRow',gr, {height:280,reloadAfterSubmit:false});
else alert("Please Select Row");
});
$("#list").hover(function(){
var gr = jQuery("#list").jqGrid('getGridParam','selrow');
});
$("#test1").click(function(){
$("#admintask").hide();
});
</script>
When I double click for the first time on a row in student table, it works fine. But when I double click on other row in the student table, it is showing the same data. I checked in the network of browser and it is not posting anything to the network as well.
Please let me know where am I making the mistake.
You have to unload the #list1 grid before loading, like below,
$("#list1 ").jqGrid('GridUnload');
jQuery("#list1").jqGrid({ ...............});
When I click in a row it is not selected, nothing happend....
This is my code, I think that scripts and CSS's are OK,
jquery-ui-1.8.16.custom.css
ui.jqgrid.css
jquery.min.js
jquery-ui.min.js
grid.locale-es.js
jquery.jqGrid.min.js
jQuery().ready(function (){
jQuery("#resTables").jqGrid({
url: "categorias.php?q=1",
datatype: "xml",
colNames: ["ID", "Categorias Es", "Categorias En", "Categorias Ru"],
colModel: [
{ name: "idCategoria", index:"idCategoria", key: true,width: 55 },
{ name: "nomCategoriaEs", index:"nomCategoriaEs", width: 250 },
{ name: "nomCategoriaEn", index:"nomCategoriaEn", width: 250, align: "right" },
{ name: "nomCategoriaRu", index:"nomCategoriaRu", width: 250, align: "right" },
],
pager: jQuery("#paginacion"),
rowList:[10,20,30],
sortname: "idCategoria",
sortorder: "desc",
viewrecords: true,
gridview: true,
autoencode: true,
caption:"Categorias" });
jQuery("#resTables").navGrid('#paginacion',{edit:true,add:true,del:false})
jQuery("#resTables").jqGrid('inlineNav',"#paginacion");
});
Thank You!!
Add this to your code..
onSelectRow: function (id) {
// do some thing
}
Here's my jQuery script
$("table#list").jqGrid({
url:'example.php',
datatype: 'json',
mtype: 'POST',
colNames:['ID', 'Position', 'Abrv', 'Department'],
colModel :[
{name:'id', index:'id', width:40, hidden: true, editrules:{edithidden:true}},
{name:'position', index:'position', width:300, editable: true, required: true},
{name:'abvr', index:'abvr', width:50, editable: true, required: true},
{name:'department', index:'department', editable: true, edittype: 'select', editoptions:{dataUrl: 'test2.php'}}
],
width: 600,
height: 250,
rownumbers: true,
pager: '#pager',
rowNum: 10,
rowList:[10,20],
sortname: 'id',
sortorder: 'ASC',
viewrecords: true,
gridview: true,
caption: 'Position',
loadError : function(xhr,st,err) {
$("#rsperror").html("Type: "+st+"; Response: "+ xhr.status + " "+xhr.statusText);
},
editurl: 'insertDB.php'
});
insertDB.php
if($_POST['oper'] == 'add'){
$position = $_POST['position'];
$department = $_POST['department'];
$query = "INSERT INTO test_position VALUES ('', '$position', '$department')";
$run = mysql_query($query);
}
Nothing happens when I submit the form. My database likewise does not update.
Is my post variables in PHP incorrect?
Is there a way to get what insertDB.php returns and display it in jQuery?
I forgot to select a database. I found out after using FireBug.