My jqGrid Script:
<script>
jQuery("#task-grid").jqGrid({
datatype: "json",
height: 'auto',
rowNum: 20,
rowList: [20,30],
colNames:['ID','RESOURCE','ROLE','SITE', 'ALLOC. TYPE', 'UNIT (%)','HOURS'],
colModel:[
{name:'ID',key:true,index:'ID', width:50, align:'center',search:false,hidden: true},
{name:'RESOURCE',index:'RESOURCE', width:150, sorttype:"text",align:'center',search:true},
{name:'ROLE',index:'ROLE',width:120 ,align:'center',search:false},
{name:'SITE',index:'SITE', width:120, align:'center',search:false},
{name:'ALLOC. TYPE',index:'ALLOCATION_TYPE', align:'center',width:120,search:false },
{name:'UNIT',index:'UNIT',align:'center',search:false},
{name:'HOURS',index:'HOURS', search:false, align:'center',sortable:false,editable:true}
],
pager: "#page",
shrinkToFit :true,
autowidth: true,
viewrecords: true,
sortname: 'RESOURCE',
sortorder: "asc",
multiselect: true,
cellEdit: true,
cellsubmit : 'clientArray',
caption: "Resource List"
}).navGrid('#page',{ edit:true,add:false,del:false,search:false,cloneToTop:true,refresh:false},
{
},{
//add options
},{
//msg: "do you really want delete this keyword? This delete affect on Eqms filter"
});
jQuery("#task-grid").jqGrid('filterToolbar', { autosearch: true });
var topPagerDiv = $('#grid_toppager')[0];
jQuery("#grid_toppager_center", topPagerDiv).remove();
</script>
Below function is appending rowId value to in hidden input
$("#addid").click(function(){
var Ids = jQuery("#task-grid").jqGrid('getGridParam','selarrrow');
var empIds = $("input[type=hidden][name=user_id]").val(Ids);
});
Hidden Input
<input type="hidden" name="user_id" value=""/>
Now I need to fetch the cell value inserted and for that I am using below function
var myGrid = $('#task-grid'),
selRowId = myGrid.jqGrid ('getGridParam', 'selrow'),
celValue = myGrid.jqGrid ('getCell', selRowId, 'HOURS');
The console log does show me the rowId selected but not its corresponding cell value. Also I am able to pass multiple rowIds checked in hidden input but not able to do for cell value.
Thanks.
First of all
jQuery("#task-grid").jqGrid('getGridParam','selarrrow');returns array of items. You can't assign the array as the value of some<input>. You can use comma separated list of items instead:.val(Ids.join(","))or you can useJSON.stringifyalternatively..val(JSON.stringify(Ids)).To place values from some columns instead of ids you can define first an empty array and then fill it with the required values using
pushmethod. At the end you can use.join(",")orJSON.stringifyto convert the array of items to the string which you can assign to<input>I recommend you additionally to use
gridview: trueoption in the grid to improve the performance and to fixname:'ALLOC. TYPE'. If you need to read some exotic formatted input elements the you should usejsonmap, but to hold thenameproperty so that it have no spaces, dots and other meta-characters. I recommend you to use allindexthe same as thename. In the case you can removeindexproperties at all fromcolModel. If you use mostlyalign:'center', search:falsethen I recommend you to change defaults forcolModelitems by usagecmTemplate: {align: 'center', search: false}. It allows you to remove many properties fromcolModeland makes it more readable and better to maintain.