jqgrid dropdown list onclick of icon - javascript

I am trying to show dropdown list in one cell of jqgrid an onClick of pencil icon(which when click the whole row become editable and dropdown list shows in debit credit )
below picture shows what i try to do
my approach is below code what i did
''''''''''''''''''''''''gridfucntion''''''''''''''''''''''''''''''''''''''''
function showMinorityEntryData(){
alert('minoritydatashow');
if($("#reportingPeriodId").val()!="" && $("#parentCmp").val()!=""){
alert('minoritydatashow1111');
// $('#masterDiv').show();
$("#grid").jqGrid({
datatype: 'json',
url:'showMinorityData.action?companyId='+companyId+"&parentCmp="+$("#parentCmp").val()+"&reportingPeriodId="+$("#reportingPeriodId").val(),
mtype: 'GET',
colNames:['Id', 'GlELEMENTNAME', 'Account Type','Pre-Acq-Amount','Share Amount','Actions'],
colModel:[
{name:'id',index:'id', width:55,editable:false,editoptions:{readonly:true,size:10},hidden:false,jsonmap:"minorityId"},
{name:'glElementName',index:'glElementName', width:100,editable:false, editrules:{required:true}, editoptions:{size:10},jsonmap:"glElementName"},
{name:'accountType',index:'accountType', width:100,editable:true, editrules:{required:true}, edittype:"select",formatter:'select',editoptions:{ value: "Debit:Debit;Credit:Credit"},editoptions:{size:10},jsonmap:"acntTypeName"},
{name:'preAcqAmount',index:'preAcqAmount', width:100,editable:true, editrules:{required:true}, editoptions:{size:10},jsonmap:"preAcqAmt"},
{name:'shareAmount',index:'shareAmount', width:100,editable:true, editrules:{required:true}, editoptions:{size:10},jsonmap:"shareAmt"},
{name:'actions',index:'actions', sortable:false,width : 50,align : 'center',formatter:actionIcons}
],
postData: {
},
rowNum:20,
rowList:[10,20,40],
height: 200,
autowidth: true,
// rownumbers: true,
pager: '#pager',
sortname: 'minorityId',
viewrecords: true,
sortorder: "asc",
caption:"Minority Interest",
emptyrecords: "Empty records",
loadonce: false,
loadComplete: function() {
},
jsonReader : {
root: "rows",
page: "page",
total: "total",
records: "records",
repeatitems: false,
cell: "cell",
id: "minorityId"
},
editurl: 'clientArray',
});
}
}
i take help from this link http://www.codeproject.com/Articles/610359/JqGrid-Inline-Editing
but when i convert accountType cell in dropdown it doesn't show type of Account type below image shows what happen
when i click on pencil icon the whole row become editable but in accountype column the dropdown doesn't show any value
what wrong i did it.
jqgrid is new for me
thanks in advance

You should include editoptions or any other property only once. So
editoptions:{ value: "Debit:Debit;Credit:Credit"},editoptions:{size:10}
need be replaced to
editoptions: { value: "Debit:Debit;Credit:Credit", size:10}

In code you have to write this
{name:'accountType',index:'accountType', width:100,editable:true, editrules:{required:true},editoptions:{size:10},edittype:"select",formatter:'select',editoptions:{ value: "Debit:Debit;Credit:Credit"},jsonmap:"acntTypeName"},
this will solve my requirement

Related

Free jqGrid, don't send new index on addrow with inlineNav

Just putting in a new grid, and everything seems to be working well, except for one thing. Using basic inline, it is sending a new incorrect key value for the column I have set with key: true. This is an auto-increment column in the database, so I just don't want to send any data for this column when ADDING, only for edit or delete is that required.
It is posting a parameter: row_id => jqg3 for the new key column and messing up my server script. So because adding the new row will auto-increment the row_id col, I don't need to send this.
How do I stop the jqGrid from sending this (row_id) index column value when saving a new added row?
free-jqgrid version is 4.14.0
$('#accts').jqGrid({
url:'/phpAJAX/Master/master_grid_v1.php',
editurl:'/phpAJAX/Master/master_grid_v1.php',
height: 'auto',
shrinkToFit: false,
width: 'auto',
datatype: 'xml',
mtype: 'POST',
postData:{
'arg1':'bol_acct'
},
colNames:[
'row_id',
'Customer',
'Trucker',
'Acct Num'
],
colModel:[
{name: 'row_id', hidden: true, key: true},
{name:'Customer', align: "center", editable: true},
{name: 'Trucker', align: "center"},
{name: 'Acct_Num', align: "center"}
],
sortname: 'Customer',
sortorder: 'desc',
viewrecords: true,
gridview: true,
caption: 'Bill of Lading Accounts',
rowNum: 10000,
pager:true
}).jqGrid('inlineNav', {
addParams: {
addRowParams: { extraparam: {'arg1':'bol_acct', 'oper':'add'} }
},
editParams: {
extraparam: {
'arg1':'bol_acct', 'oper':'edit'
}
}
})
One can use serializeSaveData callback of inline editing to modify the data, which will be send during inline editing. You can add serializeSaveData callback via
inlineEditing: {
keys: true,
extraparam: { arg1: "bol_acct" },
serializeSaveData: function (postData) {
var newPostData = $.extend(true, {}, postData);
if (newPostData.oper === "add") {
delete newPostData.id; // delete id parameter
}
return newPostData;
}
}

jqGrid wrong data format?

Im trying to put some data into jqGrid and force it to be displayed in a treeview.
My problem is, the 6th item (cid=6) is not showing in the grid. The 4th item looks like it has some subitems, but expanding this branch shows nothing. The 6th item is nowhere to find in the tree (I suppose, I've defined it as subitem of cid4).
Here is a working example of this code http://jsfiddle.net/498jhxcg/
(my production code uses POST/AJAX/JSON, the example is changed to localdata. Grid is displayed in the same wrong way in both cases.)
Is the data in wrong format, or the jqgrid is wrong defined? (btw. changing parent_id to parentid did not helped.)
var myjsondata = '{"rows":[
{"cid":"1","name":"cat1","lvl":"0","parent_id":"null","isleaf":true,"expanded":false,"loaded":true},
{"cid":"2","name":"cat2","lvl":"0","parent_id":"null","isleaf":false,"expanded":false,"loaded":true},
{"cid":"3","name":"cat3","lvl":"1","parent_id":"2","isleaf":true,"expanded":false,"loaded":true},
{"cid":"7","name":"cat7","lvl":"1","parent_id":"2","isleaf":true,"expanded":false,"loaded":true},
{"cid":"4","name":"cat4","lvl":"0","parent_id":"null","isleaf":false,"expanded":false,"loaded":true},
{"cid":"6","name":"cat6","lvl":"1","parent_id":"4","isleaf":true,"expanded":false,"loaded":true},
{"cid":"5","name":"cat5","lvl":"0","parent_id":"null","isleaf":true,"expanded":false,"loaded":true}
],"records":7,"total":1}';
$('#jgtable').jqGrid({
ExpandColumn:'id',
datastr: myjsondata,
datatype: 'jsonstring',
colNames: [
'Id',
'Name',
'Parent id',
'isLeaf?',
],
colModel: [
{ index: 'cid', name: 'cid', width:"75px"},
{ index: 'name', name: 'name', width:"75px"},
{ index: 'parent_id', name: 'parent_id',width:"75px"},
{ index: 'isleaf', name: 'isleaf', width:"75px"},
],
pager: '#pager',
rowNum: 10,
rowList:[2, 10, 25, 50, ],
height: 'auto',
minHeight: '250px',
recordpos: 'right',
viewrecords: true,
gridview: false,
treeGrid: true,
treeGridModel : 'adjacency',
treedatatype: "local",
treeReader : {
level_field: "lvl",
parent_id_field: "parent_id",
leaf_field: "isleaf",
expanded_field: "expanded",
loaded_field: "loaded",
index_field: "cid",
},
jsonReader: {
repeatitems: false,
},
});
It seems to me that you should add key: true property to the definition of cid column. You can use alternatively (or to do both things) the option jsonReader: { id: "cid" }. In the case the value of cid property of input data will be interpreted as the id of the item and the value from parent_id will be correct.
see http://jsfiddle.net/OlegKi/498jhxcg/19/

jqgrid autocomplete visible behind edit form

Hello ,
I am trying to implement jqgrid with autocomplete in one of its column. But I have very strange problem, auto-complete list is shown below the jqgird edit form.
I have included following jquery js file.
1. jquery-ui-1.10.4.custom.min.js
2. jquery.ui.core.js
3. jquery.ui.widget.js
4. jquery.ui.position.js
5. jquery.ui.menu.js
6. jquery.ui.autocomplete.js
following jqgrid js file.
1. grid.locale-en.js
2. jquery.jqGrid.min.js
3. grid.common.js
4. jqModal.js
5. jqDnR.js
6. grid.formedit.js
Following jqgrid css file.
ui.jqgrid.css
Following jquery css file.
1. jquery-ui-1.10.4.custom.css
2. demos.css
3. jquery.ui.all.css
Following code to implement jqgrid colModel.
colNames:['Id', 'First Name', 'Last Name'],
colModel:[
{name:'id',index:'id', width:55,editable:false,editoptions:readonly:true,size:10},hidden:true},
{name:'firstname',index:'lastname', width:100,editable:true,edittype:'text',
editoptions: {
dataInit: function (elem) {
myAutocomplete(elem, "${pageContext.servletContext.contextPath}/grid/autocomplete.action");
}
}},
{name:'lastname',index:'firstname', width:100,editable:true, editrules:{required:true}, editoptions:{size:10}}
],
Below is my entire jqgrid code.
var jq = jQuery.noConflict();
jq(function() {
jq("#grid").jqGrid({
url:'${pageContext.servletContext.contextPath}/grid/load.action',
datatype: 'json',
mtype: 'GET',
colNames:['Id', 'First Name', 'Last Name'],
colModel:[
{name:'id',index:'id', width:55,editable:false,editoptions:{readonly:true,size:10},hidden:true},
{name:'firstname',index:'lastname', width:100,editable:true,edittype:'text',
editoptions: {
dataInit: function (elem) {
myAutocomplete(elem, "${pageContext.servletContext.contextPath}/grid/autocomplete.action");
}
}},
{name:'lastname',index:'firstname', width:100,editable:true, editrules:{required:true}, editoptions:{size:10}}
],
postData: {
},
rowNum:20,
rowList:[20,40,60],
height: 200,
autowidth: true,
rownumbers: true,
pager: '#pager',
sortname: 'id',
viewrecords: true,
sortorder: "asc",
caption:"Users",
emptyrecords: "Empty records",
loadonce: false,
editurl:'${pageContext.servletContext.contextPath}/grid/edit.action',
loadError : function(xhr,st,err) {
console.log('display error : '+err);
jq("#rsperror").html("Type: "+st+"; Response: "+ xhr.status + " "+xhr.statusText);
},
loadComplete: function() {
},
jsonReader : {
root: "rows",
page: "page",
total: "total",
records: "records",
repeatitems: false,
cell: "cell",
id: "id"
}
});
jq("#grid").jqGrid('navGrid','#pager',
{edit:true,add:true,del:true,search:true},
{ },
{ },
{ },
{
sopt:['eq', 'ne', 'lt', 'gt', 'cn', 'bw', 'ew'],
closeOnEscape: true,
multipleSearch: true,
closeAfterSearch: true }
);
});
Here autocomplete works fine, it lists all the username but it shows behind the editForm on jqgrid. Please suggest a solution.
Thanks & Regards,
Kartik Jajal
I have solved the problem by setting the z-index property of .ui-front like below .ui-front { z-index: 1000; } in jquery ui css

JQGrid refresh data with updated data from server ater edit

I have a Jqgrid which requires editing. I have successfully managed to configure the grid to save the data after editing, however the issue is that when the data is saved the grid is not refreshed with the data present in the database. For example the version field is automatically updated by the application backend however after a edit is done it is not refreshed and the old value is shown. I have tried
afterSubmit
afterComplete
which did not work. I also placed an alert in it to verify that the function was called however the alert was not shown either. Additionally I set loadonce to false and reloadaftersubmit to true but this did not work either. I think the issue could be that I either havent configured the edit correctly or placed the above mention parameters in the incorrect location.
After a save is done (edit) the updated data (which is the WHOLE page) is returned to the Jqgrid (as json). The issue here is that the old data is shown and how do I display this updated data after the edit.
UPDATE : I found out that when I edit via the popup box the afterSubmit is executed. HOWEVER the editing takes place via the formatoptions which allows to edit the data in the table itself. Now when the data is edited and saved from the grid itself without the use of the popup I want an afterSubmit to fire to refresh the table. Where do I place my afterSubmit / How do I achieve this.
/**
* Initialize and Draw JQGrid
* #return
*/
function drawFOMJQGrid(){
var lastsel2;
jQuery("#tblGrid").jqGrid({
height: 180,
width:990,
datatype: "json",
colNames:['','Hotel','Outlet','Major Group','Item Group','Version'],
jsonReader : {
root: "regDetails",
page: "page",
total: "total",
records: "records",
repeatitems: false
},
colModel:[
{name: 'myac', width:80, fixed:true, sortable:false, resize:false, formatter:'actions', formatoptions:{keys:true}},
{name:'hotelName',index:'hotelName',align:"left",width:30,resizable:false},
{name:'majorGroupName',index:'majorGroupName',align:"left", width:20,resizable:false},
{name:'itemGroupName',index:'itemGroupName', width:30,align:"left",resizable:false},
{name:'version',index:'version', width:20,align:"right",resizable:false,editable:true,hidden: false}
],
onSelectRow: function(id){
},
/*afterSubmit : function(response, postdata){
alert("AAAA");
},
afterComplete : function(response, postdata){
alert("AAAA2");
}, */
//rowList:[10,20,30],
rowNum:5,
pager: '#divGridPg',
sortname: 'hotelName',
viewrecords: true,
sortorder: "outletName",
gridview: true,
bgiframe: true,
autoOpen: false,
caption: 'POS Item Pricing',
forceFit: false,
loadtext: 'Loading ...',
sortable: true,
loadonce: false,
editurl: "itemPricingSave.action", //"/js/itemPricing/server.js",
datatype: "json"
});
$("#tblGrid")[0].addJSONData(regGridJSONData);
$("#tblGrid").setGridParam({datatype: 'json'});
jQuery("#tblGrid").jqGrid('navGrid','#divGridPg',{edit:true,add:false,del:false,reloadAfterSubmit:true});
}
/**
* Initialize and Draw JQGrid
* #return
*/
function drawFOMJQGrid(){
var lastsel2;
jQuery("#tblGrid").jqGrid({
height: 180,
width:990,
datatype: "json",
colNames:['','Hotel','Outlet','Major Group','Item Group','Version'],
jsonReader : {
root: "regDetails",
page: "page",
total: "total",
records: "records",
repeatitems: false
},
colModel:[
{name: 'myac', width:80, fixed:true, sortable:false, resize:false, formatter:'actions', formatoptions:{keys:true}},
{name:'hotelName',index:'hotelName',align:"left",width:30,resizable:false},
{name:'majorGroupName',index:'majorGroupName',align:"left", width:20,resizable:false},
{name:'itemGroupName',index:'itemGroupName', width:30,align:"left",resizable:false},
{name:'version',index:'version', width:20,align:"right",resizable:false,editable:true,hidden: false}
],
onSelectRow: function(id){
},
/*afterSubmit : function(response, postdata){
alert("AAAA");
},
afterComplete : function(response, postdata){
alert("AAAA2");
}, */
//rowList:[10,20,30],
rowNum:5,
pager: '#divGridPg',
sortname: 'hotelName',
viewrecords: true,
sortorder: "outletName",
gridview: true,
bgiframe: true,
autoOpen: false,
caption: 'POS Item Pricing',
forceFit: false,
loadtext: 'Loading ...',
sortable: true,
loadonce: false,
editurl: "itemPricingSave.action", //"/js/itemPricing/server.js",
datatype: "json"
});
$("#tblGrid")[0].addJSONData(regGridJSONData);
$("#tblGrid").setGridParam({datatype: 'json'});
jQuery("#tblGrid").jqGrid('navGrid','#divGridPg',{edit:true,add:false,del:false,reloadAfterSubmit:true});
}
I did the following to force the grid reload:
.navGrid('#pager',
{edit:true,
add: true,
del:true,refresh:false},
{ // edit options
afterSubmit: function() {
comptes[0].clearToolbar();
comptes.jqGrid('setGridParam',{datatype:'json'}).trigger('reloadGrid');
return [true,'',false]; // no error and no new rowid
}
},
{ // add options
afterSubmit: function() {
comptes[0].clearToolbar();
comptes.jqGrid('setGridParam',{datatype:'json'}).trigger('reloadGrid');
return [true,'']; // no error
}
} ,
{ // delete options
afterSubmit: function() {
comptes[0].clearToolbar();
comptes.jqGrid('setGridParam',{datatype:'json'}).trigger('reloadGrid');
return [true,'']; // no error
}
}
);
Try to reload jqGrid with new data after all your editing process as following:
jQuery("#grid").jqGrid('setGridParam',{datatype:'json'}).trigger('reloadGrid');

jqGrid, couldn't get showlink formatter working

Hi I am trying to get showlink formatter working by following this document from trirand.
What I want to achieve is a hyperlink I can click for a edit view to update/edit records. But for some reason, the column are empty where I want show a hyperlink.
Here is my code snippets, and link is the last column:
<script type="text/javascript">
$(document).ready(function () {
$("#grid_products").jqGrid({
jsonReader: {
repeatitems: false,
id: 'Guid'
},
url: '/Product/jqgridJSON/',
datatype: 'json',
mtype: 'GET',
colNames: ['ProductCode', 'ProductDescription', 'DefaultSellPrice', 'LastCost', 'Edit'],
colModel: [
{ name: 'ProductCode', index: 'Productcode' },
{ name: 'ProductDescription', index: 'ProductDescription' },
{ name: 'DefaultSellPrice', formatter: 'currency', index: 'DefaultSellPrice' },
{ name: 'LastCost', formatter: 'currency', index: 'LastCost' },
{ name: 'MyLink',
edittype: 'select',
formatter: 'showlink',
formatoptions: { baseLinkUrl: '/Product/Update/', idName: 'Guid' }
},
],
pager: '#pager',
rowNum: 10,
rowList: [20, 50, 100, 200],
sortname: 'ProductCode',
sortorder: 'asc',
viewrecords: true,
width: 'auto',
height: 'auto',
caption: 'Products'
}).navGrid('#pager', { edit: true, add: false, del: false });
});
</script>
#{
ViewBag.Title = "JSONGrid";
}
<h2>JSONGrid</h2>
<table id="grid_products"></table>
<div id="pager"></div>
The formatter from jqGrid is working for currency, but for some reason, it just didn't shown for hyperlink.
Update:
Got it working by using custom formatter.
...
{ name: 'MyLink',
formatter: myLinkFormatter,
},
...
function myLinkFormatter (cellvalue, options, rowObjcet) {
return 'Edit this product';
}
I suppose that you fill no value in JSON input for the 'MyLink' column. Because of this the hyperlink is empty. If you want to place the link with any fixed text in column I would recommend you to use custom formatter. See the recent answer for an example.
One more possible solution way is to use formatter: 'showlink' and include jsonmap: function() { return "Edit"; } to the 'MyLink' column definition. In the case you will not need to include in the JSON data "MyLink":"Edit" for every row of data. It's important to understand that the trick works only in case of usage jsonReader: {repeatitems: false} (so it should work for your grid).
If you have another problem you should include in the text of your question the JSON data which you use.
Some small remarks to your current code:
the usage of edittype: 'select' together with formatter: 'showlink' has no sense. You should remove it if you will do use formatter: 'showlink'.
the parameter height: 'atuo' should be height: 'auto'.
pager: $('#pager') is better to replace to pager: '#pager'. If you use pager: $('#pager'), the jqGrid will replace it internally to pager: '#pager' and the object $('#pager') will be discarded.
If you use jsonReader: { id: 'Guid'} and you don't plan to show the guids to the user you can remove the 'Guid' column from the grid. The id (the Guid in your case) will be used to assign ids of <tr> elements (table rows) of the grid. So you don't need to hold the same information twice

Categories