gpt4 book ai didi

javascript - 如何自动刷新jqgrid?

转载 作者:行者123 更新时间:2023-11-30 10:39:00 24 4
gpt4 key购买 nike

我使用以下脚本将 sql 数据库中的详细信息绑定(bind)到 jqgrid。添加、编辑、删除工作正常,我的问题是,如果我尝试添加、编辑、删除数据jqgrid 它在数据库中更新但在我刷新页面然后数据显示在jqgrid中后没有显示在jqgrid中。如何在点击提交按钮后自动刷新jqgrid?

    <script type="text/javascript">


$(document).ready(function(){
var mydata=new Array();

$.extend({
getValues: function(url) {
var result = null;

$.ajax({

url: url,
type: 'POST',
data:'Param=value',
async:false,
success: function(data) {
result=JSON.parse(data);
}
});
return result;
}

});

mydata = $.getValues(Some url);//get the data from the url

$("#datagrid").jqGrid({

datatype: "local",
data: mydata,
colNames:['companyid','company', 'price', 'Change','perchange','LastUpdated'],
colModel:[
{name:'companyid',index:'companyid', width:100,editable:true,editoptions:{size:10}},
{name:'company',index:'company', width:100,editable:true},
{name:'price',index:'price', width:100,editable:true,editoptions:{size:10}},
{name:'Change',index:'Change', width:100,editable:true,editoptions:{size:25}},
{name:'perchange',index:'perchange', width:100, align:"right",editable:true,editoptions:{size:10}},
{name:'LastUpdated',index:'LastUpdated', width:200, align:"right",editable:true,editoptions:{size:10}}
],
rowNum:10,
rowList:[10,20],
loadonce: true,
pager: '#navGrid',
sortname: 'companyid',
sortorder: "asc",
height: 210,
width:600,
onSelectRow: function(id){
getID = jQuery("#datagrid").jqGrid('getCell', id, 'companyid')
},
viewrecords: true,
caption:"JQ GRID"
});

jQuery("#datagrid").jqGrid('navGrid','#navGrid',{edit:true,add:true,del:true, addtext: 'Add', edittext: 'Edit', deltext: 'Delete'},

//For Edit
{
closeOnEscape: true,
closeAfterEdit: true,
reloadAfterSubmit:true,
closeOnEscape: true,
url:'Some url'

},
// For Add
{

closeOnEscape: true,
closeAfterAdd: true,
reloadAfterSubmit: true,
closeOnEscape: true,
url: 'Some url'
},
// For Delete
{
url:'Some url',
closeAfterDelete: true,
reloadAfterSubmit: true,
closeOnEscape: true,
onclickSubmit: function(e, postdata)
{
e.url = 'Some url'
}
}


);


});


</script>

最佳答案

你需要触发reloadGrid :-

  $("#datagrid").trigger("reloadGrid");

关于javascript - 如何自动刷新jqgrid?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12275178/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com