grid is not loading after edit - jqgrid

1)I am using JQGrid I am able to edit the roa and post the data but the grid is not loading after submit.I know I am missing something but not sure what is.I looked the forum and google around but no result.Any help would be appriciated.Below is the code for your reference
$(document).ready(function() {
jQuery("#g-grid").jqGrid({
datatype: "json",
mtype: 'GET',
url: '${createLink(controller: 'response', action: 'listRequestsAsJSON')}',
colNames: ['Entry Type', 'Life Cycle Status','Start Date','End Date','Key Stakeholder Publish'
,'Remarks','RoadmapGroup','EventStatus'],
colModel: [
{name:'roadMapEntryTypeCode',index:'roadMapEntryTypeCode', editable:true,
edittype:"select",editoptions:{value:initdropdownlist('LIFECYCLE')}},
{name:'lifeCycleStatusCode',index:'lifeCycleStatusCode',editable:true,
edittype:"select",editoptions:{value:initdropdownlist('LIFECYCSTAT')}},
{name:'roadMapEventStartDate',index:'roadMapEventStartDate',editable:true,
formatter:'date',editoptions:{dataInit:datePick}},
{name:'roadMapEventEndDate',index:'roadMapEventEndDate',editable:true,
formatter:'date',editoptions:{dataInit:datePick}},
{name:'keyStakeholderPublisherCode',index:'keyStakeholderPublisherCode',editable:true,
edittype:"select",editoptions:{value:initdropdownlist('KEYSTAKEPUB')}},
{name:'roadMapEventRemarksText',index:'roadMapEventRemarksText',editable:true,
edittype:"textarea",editoptions:{rows:"2",cols:"20"}},
{name:'roadMapGroupName',index:'roadMapGroupName',editable:true
,editoptions:{size:10}},
{name:'roadMapEventStatusCode',index:'roadMapEventStatusCode',editable:true,
edittype:"select",editoptions:{value:initdropdownlist('EVENTSTAT')}}
],
pager: jQuery('#g-pager'),
ondblClickRow: function(rowid) {
jQuery(this).jqGrid('editGridRow', rowid,
{
closeAfterEdit:true,
afterSubmit: function(response,postdata){
var json=response.responseText;
var result=eval("("+json+")");
return [result.status,result.message];},
editCaption: "Edit LifeCycle Roadmap",
bSubmit: "Save",
bCancel: "Cancel",
bClose: "Close",
saveData: "Data has been changed! Save changes?",
bYes : "Yes",
bNo : "No",
bExit : "Cancel",
reloadAfterSubmit:true
});},
viewrecords: true,
gridview: true,
editurl:'${createLink(controller: 'response', action: 'updateAssetLifecycleRoadmap')}'+"?AssetId="+${assetInstance?.id}
});
});
datePick = function(elem){jQuery(elem).datepicker({dateFormat:"mm/dd/yy"});};
$("#bedata").click(function(){
var gr = jQuery("#g-grid").jqGrid('getGridParam','selrow');
if( gr != null ) jQuery("#g-grid").jqGrid('editGridRow',gr,{height:280,reloadAfterSubmit:false});
else alert("Please Select Row");
});
initdropdownlist = function(colName) {
var options = ":";
$.ajax({
async: false,
type: "GET",
url: '${createLink(controller: 'response', action: 'getDropDownList')}?' + "sel=" + colName,
contentType: "application/json; charset=utf-8″,
dataType: "json",
success: function(dropDownListMap) {
for (var i = 0; i < dropDownListMap.option.length; i++) {
options +=";"+dropDownListMap.option[i].value + ":" +dropDownListMap.option[i].label;
}
}
});
return options;
}
2)The other thing is with the edit button,there is no action fired on clicking the button,any idea?
<input type="BUTTON" id="bedata" value="Edit Selected"/>

Try:
$('#unmatchedgrid').setGridParam("ur url and params here" )
jQuery("#g-grid").trigger('reloadGrid')
from the second time you load the grid by fetching the selected parameters (if any)

Related

kendo ui grid dropdownlist cannot pass its value while adding a new record

The below case refers to:http://demos.telerik.com/kendo-ui/grid/editing-custom
The adding screen works, but the add failed because of the dropdownlist cannot get value.
The problem is: when add a new record, and then select a Curve Term (not the default value), the dropdown cannot get any value, that is, the json backend is: "curvetermid":""
The code is as below:
<div id="grid"/>
var dataSource = new kendo.data.DataSource ({
batch:true,
transport:{
read: function (options) {
$.ajax({
type: "POST",
url:"",
data:"/idx/list",
dataType:"json",
contentType: "application/json; charset=utf-8",
success: function(result) {
options.success(result);
}
})
},
create: function(options) {
$.ajax({
type: "POST"
,url:"/create"
,dataType:"json"
,contentType: "application/json; charset=utf-8"
,data:kendo.stringify(options.data.models)
,success:function(result) {
options.success(result);
}
});
},
parameterMap:function(options,operation) {
return kendo.stringify(options.models);
}
},
schema:{
data: result.data,
total:result.total,
model:{
id:idKey,
fields:{
idKey: {type:"number"},
**curveterm: {validation: {required: true}}**
}
}
}
});
$("#grid").kendoGrid({
dataSource:dataSource,
columns: [
{field: "idKey", title: "ID"},
**{field: "curvetermid",
title: "Curve Term",
editor: fnDdlCurvetermEditor,
template: "#=curveterm.curvetermname#"}
]**,
editable:{mode:"popup", confirmation:"Are you sure you want to remove this item?"}
});
function fnDdlCurvetermEditor(container,options) {
var data = [{"curvetermid":0,"curvetermname":"NA","isactive":1}, {"curvetermid":1,"curvetermname":"AAA","isactive":1},{"curvetermid":2,"curvetermname":"BBB","isactive":1}];
var ddlVar = $('<input id="curvetermid" name="curvetermid" '
+ ' data-value-field="curvetermid" '
+ ' data-text-field="curvetermname"'
+ ' data-bind="value: ' + options.field + '"/>')
.appendTo(container)
.kendoDropDownList({
dataTextField: "curvetermid",
dataValueField: "curvetermname",
dataSource: data
});
}

Change edittype on addparam and editparam in JqGrid inline Navigator

I have two dropdowns in jqgrid inline navigator. I want to enable both dropdown only for add mode,and only one dropdown for edit mode.
grid = $("#gridTable");
grid.jqGrid({
colModel: [
{ name: 'empId' , width: "250",editable:true,edittype: 'select',editoptions:{value: {"Emp1","Emp2"}}, formoptions:{ rowpos:1, label: "Emp Id", elmprefix:"(*)"},editrules:{required:true}},
{ name: 'Address' , width: "250",editable:true,edittype: 'select',editoptions:{value: {"Emp Add1","Emp Add2"}}, formoptions:{ rowpos:2, label: "Address", elmprefix:"(*)"},editrules:{required:true}}
],
pager: '#gridTablePager',
colNames:[ 'empId', 'Address'],
rowList:[10,20,50,100,200,500],
datatype: "jsonstring",
datastr: dataInDb,
jsonReader: { repeatitems: false },
viewrecords: true,
height: 300,
ignoreCase: true
});
What code I should add for this?
Could anyone help?
you can do something like this.
grid.jqGrid('inlineNav', "#" + paginator, {
addParams: {
addRowParams: {
url: baseUrl + 'Plantilla/InsertCaracteristicaPlantillaTemp',
mtype: "POST",
oneditfunc: function (rowid) {
InitModel(rowid, 'I');
}
},
editParams: {
url: baseUrl + 'Plantilla/UpdateCaracteristicaPlantillaTemp',
mtype: "POST",
oneditfunc: function (rowid) {
InitModel(rowid, 'U');
}
});
function InitModel(rowid, Operation){
if(Operation == "U")
$("#" + rowid + "_fielName").attr("disabled", true);
}
Now, with that function you can enable and disable fields when you want.

Kendo Grid groupping

I read this topic and use open source edition of kendo web, my current version is Kendo UI Web v2012.3.1114. My problem is exist as the link above and I could not solve it.
Part of my script is here:
function load() {
var grid = $("#grid").data("kendoGrid");
if (grid) {
//destroy the previous Grid instance
grid.destroy();
//clean up the html
grid.wrapper.html("");
}
var crudServiceBaseUrl = "WebForm.aspx",
//datasource = null;
dataSource = new kendo.data.DataSource({
transport: {
read: {
url: crudServiceBaseUrl + "?q=load&sql=" + $("#tbSQL").val(),
dataType: "jsonp"
},
update: {
url: crudServiceBaseUrl + "?q=update&sql=" + $("#tbSQL").val(),
dataType: "jsonp"
},
destroy: {
url: crudServiceBaseUrl + "?q=destroy&sql=" + $("#tbSQL").val(),
dataType: "jsonp"
},
create: {
url: crudServiceBaseUrl + "?q=create&sql=" + $("#tbSQL").val(),
dataType: "jsonp"
},
parameterMap: function (options, operation) {
if (operation !== "read" && options.models) {
return { models: kendo.stringify(options.models) };
}
}
},
batch: true,
pageSize: 20,
schema: getmodel()
$("#grid").kendoGrid({
dataSource: dataSource,
navigatable: true,
//pageable: true,
selectable: true,
//groupable: true,
sortable: true,
pageable: {
refresh: true,
pageSizes: true
},
height: 500,
toolbar: ["create", "save", "cancel"],
columns: getColumns(),
editable: true
});
}
Every thing is ok, but only after loading page I can only One time group by headers.
It seems that this behavior is improved in the latest version of KendoUI 2012 Q3 SP1 (v.2012.3.1315), where the grouping is working as expected. For convenience I created this sample.

Jqgrid treegrid performance

I have tried gridview:ture , loadui:block but still it takes more time to display treegrid after loading. my json contains more then 2044 data. I am using firefox version 3.6
my code is given below
**
Glcm= [{name:'id',index:'id', label:'Id',hidden:true,key:true, Enabled:false,jsonmap:"id"},{name:'text',index:'text',label:'Global Ledger',width:400,jsonmap:"text",formatter:gLCheckbox},{name:'additionalInfo',index:'additionalInfo',label:'additionalInfo',hidden:true,jsonmap:"additionalInfo"},
],
**
GlTree.jqGrid({
url: 'GlTreeStructure.action',
datatype: "json",
mtype: "POST",
colModel:Glcm,
width:outerwidthGL,
height:300,
rowNum:-1,
pager: '#ptreeList',
viewrecords: true,
caption:"Global Ledger",
toolbar: [true,"top"],
gridview:true,
treeGrid: true,
pginput:false,
pgtext:"",
pgbuttons:false,
loadui:'block',
deepempty:true,
ignoreCase: true,
autoencode:true,
jsonReader :{root: 'glList',
cell:"",
repeatitems: false
},
treeReader : {
level_field: "level",
left_field:"lft",
right_field: "rgt",
leaf_field: "isLeaf",
parent_id_field: "parentId",
expanded_field: "expanded",
loaded: "loaded"
},
treedatatype: "json",
treeGridModel:'adjacency',
ExpandColClick: true,
loadonce:true,
ExpandColumn : 'text',
// cellSubmit: 'remote',
gridComplete:function()
{
myData = GlTree.jqGrid('getRowData');
}
});
// this function is used in formatter to display radio buttons
function gLCheckbox(amount,options,rData)
{
if(rData.additionalInfo === 'G')
return '<div id ="checkglId"><input type="radio" id="radioId" name ="radioName" value="' +rData.text+'" align = "center",offval="off" onclick="selectGLElement(\''+rData.id+'\');" /> '+amount + '</div>';
else
return amount;
}
I finally got the answer for my question. I am now able to auto large number of data into treegrid.
I have used treegrid adjaceny model aud autoloaded the tree on demand. But my treenode gets loaded on onSelectRow.
onSelectRow: function(id){
var data = $(this).jqGrid("getRowData", id);
getChildTree(data,data.glId);
}
function getChildTree(postdata,id)
{
$.ajax({
type: "GET",
url: "GlChildTreeStructure.action?glId="+id,
dataType: "json",
success: function(json){
JsonDataObj = json;
for(var i=0;i<JsonDataObj.ChildTreeList.length;i++){
if(JsonDataObj.ChildTreeList.isLeaf==true){
//alert("JsonDataObj.ChildTreeList : "+JsonDataObj.ChildTreeList[i].glId)
$("#GlTreeStructureGrid").jqGrid("addChildNode",JsonDataObj.ChildTreeList[i].glId, JsonDataObj.ChildTreeList[i].parentId,
{
"glId":JsonDataObj.ChildTreeList[i].glId,
"text":JsonDataObj.ChildTreeList[i].text,
"additionalInfo":JsonDataObj.ChildTreeList[i].additionalInfo,
"alternativeParent":JsonDataObj.ChildTreeList[i].alternativeParent,
"parentId":JsonDataObj.ChildTreeList[i].parentId,
"parent":JsonDataObj.ChildTreeList[i].parentId,
"dataType":JsonDataObj.ChildTreeList[i].dataType,
"periodType":JsonDataObj.ChildTreeList[i].periodType,
"glPresentationOrder":JsonDataObj.ChildTreeList[i].glPresentationOrder,
"extendedLink":JsonDataObj.ChildTreeList[i].extendedLink,
"parentCalculation":JsonDataObj.ChildTreeList[i].parentCalculation,
"isLeaf":JsonDataObj.ChildTreeList[i].isLeaf,
"level":JsonDataObj.ChildTreeList[i].level,
"lft":JsonDataObj.ChildTreeList[i].lft,
"expanded":JsonDataObj.ChildTreeList[i].expanded,
"loaded":JsonDataObj.ChildTreeList[i].loaded,
"icon":JsonDataObj.ChildTreeList[i].icon,
"rgt":JsonDataObj.ChildTreeList[i].rgt});
}else{
// alert("JsonDataObj.ChildTreeList : "+JsonDataObj.ChildTreeList[i].glId)
$("#GlTreeStructureGrid").jqGrid("addChildNode",JsonDataObj.ChildTreeList[i].glId, JsonDataObj.ChildTreeList[i].parentId,
{
"glId":JsonDataObj.ChildTreeList[i].glId,
"text":JsonDataObj.ChildTreeList[i].text,
"additionalInfo":JsonDataObj.ChildTreeList[i].additionalInfo,
"alternativeParent":JsonDataObj.ChildTreeList[i].alternativeParent,
"parentId":JsonDataObj.ChildTreeList[i].parentId,
"dataType":JsonDataObj.ChildTreeList[i].dataType,
"parent":JsonDataObj.ChildTreeList[i].parentId,
"periodType":JsonDataObj.ChildTreeList[i].periodType,
"glPresentationOrder":JsonDataObj.ChildTreeList[i].glPresentationOrder,
"extendedLink":JsonDataObj.ChildTreeList[i].extendedLink,
"parentCalculation":JsonDataObj.ChildTreeList[i].parentCalculation,
"isLeaf":JsonDataObj.ChildTreeList[i].isLeaf,
"level":JsonDataObj.ChildTreeList[i].level,
"lft":JsonDataObj.ChildTreeList[i].lft,
"expanded":JsonDataObj.ChildTreeList[i].expanded,
"loaded":JsonDataObj.ChildTreeList[i].loaded,
"icon":JsonDataObj.ChildTreeList[i].icon,
"rgt":JsonDataObj.ChildTreeList[i].rgt});
}
}
},
});
}

Datainit is giving null

Can somebody please help me understand why the dataInit function wouldn't have a value for the field. I have the following added to the categories column in my grid.
dataInit: function (elem)
{
var v = $(elem).val();
alert("In data init val is " + v);
$(elem).trigger('change');
}
I get a null value in the alert and the trigger function doesn't fire either.
If this question about editoptions and using server data. I have got the answer. This is happen because your data is not local but from server. Using server(not local data), browser need several time to load into the select element and change to the selected option as in row.
So, the $(elem).val(); from dataInit is null because it is still null on that time, u have to wait about 100 ms(on my case).
Here my code, the case is about loading provinces with its cities on .
dataInit: function (elem) {
$(elem).ready(loadCities);
},
I create function loadCities function out of jqgrid definition
function loadCities() {
setTimeout('$.ajax({type: "GET",data: "", url: "<?php echo base_url();?>index.php/cities/cities_select_options_by_prov_and_store/"+$("#province").val()+"/"+$("#id").val(), success: function(data){ $("#city").html(data);}})',100);
}
here are my complete code
var gridStores = jQuery('#gridStores');
function loadCities() {
setTimeout('$.ajax({type: "GET",data: "", url: "<?php echo base_url();?>index.php/cities/cities_select_options_by_prov_and_store/"+$("#province").val()+"/"+$("#id").val(), success: function(data){ $("#city").html(data);}})',100);
}
var resetCitiesValues = function () {
gridStores.setColProp('#city', { editoptions: { value: ':- Choose Province First -'} });
};
gridStores.jqGrid({
url:'<?php echo base_url();?>index.php/stores/stores_json',
datatype: 'json',
colNames:['ID','Name'],
colModel:[
{name:'id',index:'stores.id', hidden:true,editable:true},
{name:'province',index: 'provinces.name', width:100,stype:'text',sorttype:'text',editable:true,editrules:{required:true},edittype:"select",editoptions:{dataUrl:'<?php echo base_url();?>index.php/provinces/provinces_select_options',
dataInit: function (elem) {
$(elem).ready(loadCities);
},
dataEvents: [{type: 'change',fn: function(e) {$.ajax({type: "GET",data: "", url: "<?php echo base_url();?>index.php/cities/cities_select_options/"+$(this).val(), success: function(data){ $("#city").html(data);}})}}]}},
{name:'city',index: 'cities.name', width:100,stype:'text',sorttype:'text',editable:true,editrules:{required:true},edittype:"select", editoptions:{ value: ':- Choose Province First -', defaultValue:'- Choose City -'}},
],
width:'600',
rownumbers: true,
rownumWidth: 40,
rowNum:10,
rowList : [20,30,50],
viewrecords: true,
pager: '#pagerStores',
sortname: 'stores.id',
sortorder: "desc",
searchOn:"false",
editurl: "<?php echo base_url();?>index.php/stores/edit"
});
jQuery("#gridStores").jqGrid('navGrid','#pagerStores',
{
edit:true,
add:true,
del:true,
search:false,
refresh:true,
recreateForm:true,
viewPagerButtons:false
},
{
closeAfterEdit:true,
closeAfterAdd:true,
reloadAfterSubmit:true,
editData: {<?php echo $this->security->get_csrf_token_name()?>: '<?php echo $this->security->get_csrf_hash() ?>'},
recreateForm:true,
viewPagerButtons:false
},
{
closeAfterEdit:true,
closeAfterAdd:true,
reloadAfterSubmit:true,
editData: {<?php echo $this->security->get_csrf_token_name()?>: '<?php echo $this->security->get_csrf_hash() ?>'}
},
{
delData: {<?php echo $this->security->get_csrf_token_name()?>: '<?php echo $this->security->get_csrf_hash() ?>'},
},
{
caption: "Search",
Find: "Find",
Reset: "Reset",
sopt : ['eq', 'cn'],
matchText: " match",
rulesText: " rules",
stringResult: true
}
);
jQuery("#gridStores").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : false});
I have the same problem too. In order to accomplish this: jqgrid incorrect select drop down option values in edit box in dataInit and dataEvents v = $(elem).val(); and var v = parseInt($(e.target).val(), 10); give me back null. If i put in v the right values all the other works fine!
The elem is now already an object, so JQuery is not needed to get its properties.
Just use var v = elem.value;

Resources