jqGrid ondblClickRow not working as desired - php

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({ ...............});

Related

jQgrid delete id return row id

$(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];
}

JqGrid Delete Function

I have some problem, I want to delete some row using JqGrid plugin
Here's my php delete function, the database colum for id is idms_department
if($oper == 'del'){
$deptid = $_REQUEST['idms_department'];
$del = "DELETE FROM ms_department WHERE idms_department =" . $deptid;
if(mysql_query($del)){
"Delete Successfull";
} else {
die("Error Delete: " .mysql_error()."SQL : " .$del);
}
mysql_close();
}
and my jqgrid setting
<script type="text/javascript">
$(document).ready(function() {
//alert("start");
jQuery("#departments").jqGrid({
mtype:'GET',
url:'functions/get_dept.php',
editurl:'functions/edit_dept.php',
datatype: "JSON",
colNames:['Department ID','Department'],
colModel:[
{name:'idms_department',index:'idms_department', width:150, editable:true,add:true, del:true, key:true},
{name:'department',index:'department', width:800,editable:true, add:true, del:true}
],
loadComplete: function () {
alert("OK");
},
loadError: function (jqXHR, textStatus, errorThrown) {
alert('HTTP status code: ' + jqXHR.status + '\n' +
'textStatus: ' + textStatus + '\n' +
'errorThrown: ' + errorThrown);
alert('HTTP message body (jqXHR.responseText): ' + '\n' + jqXHR.responseText);
},
rowNum:10,
rowList:[5,10,15],
pager: '#pager-departments',
sortname: 'idms_department',
viewrecords: true,
jsonReader: {repeatitems: true, idms_department: "idms_department" },
sortorder: "asc",
caption:"Example Departments"
});
jQuery("#departments").jqGrid('navGrid','#pager-departments',{edit:true,add:true,del:true});
jQuery("#departments").jqGrid('gridResize',{minWidth:350,maxWidth:850,minHeight:80, maxHeight:350});
//alert("end");
});
</script>
How to get value of idms_department, because I see in my firebug, the idms is not recognizing (null) so the sql function is falling.
I am pasting example code for you please refer it, may be it will be help you.
jQuery("#list_requisitos").jqGrid(
{
url:'../ajax/common_form_detail.php?form_id='+form_id,
editurl:'../ajax/common_form_edit.php?form_id='+form_id,
datatype: "json",
colNames:['D','ID','AREA','PIN Transportador','Fecha creacion','Aprob. Gestor Operativo','Aprob. Gestor Administrativo','Usuario que registra','Contratista','Fecha EjecucionDe la Tarea','Periodo','Anexos'],
colModel:[{name:'boton_grupos_tematicos',index:'boton_grupos_tematicos',sortable:false, align:'center',width:'50',search:false},{name:'id',index:'id',editable:false,hidden:true},{name:'object_area',
index:'object_area',
formoptions:{elmsuffix:''},
editable:true,
editrules:{required:true},
hidden:false,
search:true,
edittype:'select',
formatter:'select',
editoptions: {value: ''}
},{name:'pin_transportador',
index:'pin_transportador',
formoptions:{elmsuffix:''},editrules:{required:true},editable:true,
hidden:false,
search:true,
editoptions: {size:80, maxlength: 1000}
},{name:"created_date",
index:"created_date",
formoptions:{elmsuffix:"(aaaa-mm-dd)"},
sorttype:"date", editoptions:{dataInit: function(element) {$(element).datepicker({dateFormat: "yy-mm-dd"})}},
search:true,
type:"text",
searchoptions:
{
dataInit: seleccionarFecha,
attr: {title: "Selecciona una fecha"}
}
},{name:'app_by_codinator',
index:'app_by_codinator',
editable:true,
search:true,
edittype:'select',
formatter:'select',
editoptions: {value: '0:NO;1:SI;-1:RECHAZADO'}},{name:'app_by_manager',
index:'app_by_manager',
editable:true,
search:true,
edittype:'select',
formatter:'select',
editoptions: {value: '0:NO;1:SI;-1:RECHAZADO'}},{name:"user_id",index:"user_id",type:"text",editable:false,hidden:false},{name:"contractor_id",index:"contractor_id",type:"text",editable:false,hidden:true},{name:"actual_task_done_date",index:"actual_task_done_date",type:"text",editable:false,hidden:false,editoptions:{dataInit: function(element) {$(element).datepicker({dateFormat: "yy-mm-dd"})}},},{name:"sumerized_date",index:"sumerized_date",type:"text",editable:false,hidden:false},{name:"attachments",index:"attachments",type:"text",editable:false,hidden:false}],
rowNum:20,
rowList:[20,50,100],
pager: '#pager_requisitos',
sortname: 'id',
viewrecords: true,
multiselect: true,
sortorder: "asc",
autowidth: true,
height: 400,
width: 900,
caption:"RG05 IN340_pin_transportador",
});
jQuery("#list_requisitos").jqGrid('navGrid','#pager_requisitos',{ edit:true,add:true,del:true,search:false},{width:780,recreateForm:true},{width:780,recreateForm:true})
.jqGrid('filterToolbar',{stringResult: false,searchOnEnter : false, autosearch: true})
});
});
The documentation of delGridRow describes what will be sent to the server on Delete operation. The name of rowid is id instead of idms_department which you use in your code (see the line $deptid = $_REQUEST['idms_department'];). You should either use the name 'id' in the statement or add prmNames: {id: "idms_department"} option to jqGrid. It changes the default name of id used in Add/Edit/Delete operation.
Additionally I would recommend you remove non existing properties add:true, del:true from colModel and index properties which value are the same as values of name properties, remove default value repeatitems: true from jsonReader and add gridview: true and autoencode: true to the grid. You can additionally remove {edit:true,add:true,del:true} option (remove the last parameter) of navGrid because all the values are default (see the documentation).
$(".deletethisrecord").live('click',function(e){ e.preventDefault();
toDelete = $(this).parent().parent().attr('id');
$("#list2").jqGrid(
'delGridRow',
toDelete,
{ url: '<?php echo $edit; ?>',
reloadAfterSubmit:false}
);
});
});
use some thing like this. place delete in your record list.

jqgrid don't call successfunc after addrow

I try to work with the jqgrid and have now the problem that the function successfunc, aftersavefunc, errorfunc and afterrestorefunc not will be called.
My code:
$("#list-nxfeatures").jqGrid({
url:'lib/nxfeatures.php',
datatype: 'xml',
mtype: 'GET',
colNames:['Id','Name', 'Description','Default','Allow change','Nolimit'],
colModel :[
{name:'id', index:'id', width:55},
{name:'name', index:'datasetid', width:150, editable:true},
{name:'description', index:'featureid', width:200, editable:true},
{name:'defaultvalue', index:'defaultvalue', width:80, align:'center',editable:true, edittype:"checkbox", editoptions: {value:"1:0"}},
{name:'allowchange', index:'allowchange', width:100, align:'center',editable:true, edittype:"checkbox", editoptions: {value:"1:0"}},
{name:'nolimit', index:'nolimit', width:80, align:'center',sortable:false,editable:true, edittype:"checkbox", editoptions: {value:"1:0"}}
],
pager: '#pager-nxfeatures',
rowNum:10,
rowList:[10,20,30,100],
rownumbers: true,
sortname: 'id',
sortorder: 'desc',
viewrecords: true,
gridview: true,
caption: 'Features',
editurl: "lib/modifynxfeatures.php",
height: 220,
width: 800
});
jQuery("#list-nxfeatures").jqGrid('navGrid',"#pager-nxfeatures",{edit:false,add:false,del:true});
jQuery("#list-nxfeatures").jqGrid('inlineNav', "#pager-nxfeatures", { addParams: {
rowID: "neu3",
addRowParams: {
oneditfunc: function () {
alert("edited");
},
successfunc: function (response) {
alert("success");
return true;
},
aftersavefunc: function (response) {
alert("aftersave");
},
errorfunc: function (rowid, response) {
alert("errorfunc");
},
afterrestorefunc :function (rowid) {
alert("afterrestorefunc");
}
}
}
});
jQuery("#list-nxfeatures").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : false});
What is wrong on my code?
The oneditfunc is work perfect.
Found your post as I had the same issue as yours. Found the solution. Posting it here for others reference.
addParams:{
addRowParams:{
oneditfunc:function(){
alert("edited");
}
}
},
editParams:{
successfunc:function(response){
alert("success");
return true;
}
}

jqGrid: How to insert data in database using add row in navigator?

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.

JqGrid Reload not working

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.

Categories