请帮帮我。如何使用我添加的新数据reload jQgrid
(在提交按钮添加后)。
我使用代码点火器,我处理向控制器添加数据然后插入数据库,添加后,我希望我的jqGrid重新加载新数据。
这是关于jQgrid添加导航按钮的操作(但添加后仍然没有重新加载)
reloadAfterSubmit:true,
afterSubmit: function ()
{
$(this).jqGrid('setGridParam', {datatype:'local'});
return [true,'',false]; // no error and no new rowid
}
这是JQ Grid的完整代码:
var grid_datax =
[
<?php
foreach($propas as $propas){
?>
{idasset:"<?php echo $propas['name']; ?>",property:"<?php echo $propas['prop']; ?>",desc:"<?php echo $propas['description']; ?>",val:"<?php echo $propas['value']; ?>",idprop:"<?php echo $propas['idprop'];?>",description:"<?php echo $propas['description'];?>",value:"<?php echo $propas['value'];?>"},
<?php
}
?>
];
var grid_selector = "#grid-tablex";
var pager_selector = "#grid-pagerx";
jQuery(grid_selector).jqGrid({
//direction: "rtl",
data: grid_datax,
datatype: "local",
height: 250,
colNames:[' ','Asset','Property','Description','Value','','',''],
colModel:[
{name:'myac',index:'', width:80, fixed:true, sortable:false, resize:false,
formatter:'actions',
formatoptions:{
keys:true,
delOptions:{
url : 'add_asset_prop',
mtype : "GET",
onclickSubmit: function (options, rowid) {
var rowData = $(this).jqGrid("getRowData", rowid);
// now we can modify the URL used in the Delete operation
options.url += "?" + $.param({
idasset: <?php echo $idasset;?>,
idprop: rowData.idprop,
description : rowData.description,
value : rowData.value
});
return {}; // you can return additional data which will be sent to the server
}
},
//editformbutton:true, editOptions:{recreateForm: true, beforeShowForm:beforeEditCallback}
}
},
{name:'idasset',index:'idasset', width:90, hidden: true, editable: true,edittype:"select",editoptions:{value:"<?php echo $idasset.":".$name;?>"}, editrules: {edithidden:false}},
{name:'property',index:'property', width:90, editable: true,edittype:"select",editoptions:{value:"<?php echo $jj; ?>"}},
{name:'desc',index:'desc', width:70,editable: true,editoptions:{size:"20",maxlength:"30"}},
{name:'val',index:'val', width:150, editable: true},
{name:'idprop', index:'idprop', hidden: true ,hidedlg: true, editable: true, editrules: {edithidden:false} },
{name:'description', index:'description', hidedlg: true,hidden: true , editable: true, editrules: {edithidden:false} },
{name:'value', index:'value', hidden: true , hidedlg: true, viewable:false, editable: true, editrules: {edithidden:false} }
],
viewrecords : true,
rowNum:10,
rowList:[10,20,30],
pager : pager_selector,
altRows: true,
//toppager: true,
loadonce: true,
multiselect: true,
//multikey: "ctrlKey",
multiboxonly: true,
loadComplete : function() {
var table = this;
setTimeout(function(){
styleCheckbox(table);
updateActionIcons(table);
updatePagerIcons(table);
// enableTooltips(table);
}, 0);
},
editurl: $path_base+"<?php echo "master_data/protected_assets/add_asset_prop/"; ?>",//nothing is saved
caption: "Manage Asset Property",
autowidth: true
});
这是nav Buttons
jQuery(grid_selector).jqGrid('navGrid',pager_selector,
{ //navbar options
edit: true,
editicon : 'icon-pencil blue',
add: true,
addicon : 'icon-plus-sign purple',
del: false,
delicon : 'icon-trash red',
search: true,
searchicon : 'icon-search orange',
refresh: true,
refreshicon : 'icon-refresh green',
view: true,
viewicon : 'icon-zoom-in grey',
},
{
//edit record form
//closeAfterEdit: true,
recreateForm: true,
beforeShowForm : function(e) {
var form = $(e[0]);
form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
style_edit_form(form);
},
afterSubmit: function () {
$(this).jqGrid('setGridParam', {datatype:'xml'});
return [true,'',false]; // no error and no new rowid
}
},
{
//new record form
closeAfterAdd: true,
recreateForm: true,
reloadAfterSubmit:true,
afterSubmit: function ()
{
$(this).jqGrid('setGridParam', {datatype:'xml'});
return [true,'',false]; // no error and no new rowid
}
},
{
//delete record form
recreateForm: true,
beforeShowForm : function(e) {
var form = $(e[1]);
if(form.data('styled')) return false;
form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
style_delete_form(form);
form.data('styled', true);
},
onClick : function(e) {
alert(1);
}
},
{
//search form
recreateForm: true,
afterShowSearch: function(e){
var form = $(e[0]);
form.closest('.ui-jqdialog').find('.ui-jqdialog-title').wrap('<div class="widget-header" />')
style_search_form(form);
},
afterRedraw: function(){
style_search_filters($(this));
}
,
multipleSearch: true,
/**
multipleGroup:true,
showQuery: true
*/
},
{
//view record form
recreateForm: true,
beforeShowForm: function(e){
var form = $(e[0]);
form.closest('.ui-jqdialog').find('.ui-jqdialog-title').wrap('<div class="widget-header" />')
}
}
)
function style_edit_form(form) {
//update buttons classes
var buttons = form.next().find('.EditButton .fm-button');
buttons.addClass('btn btn-sm').find('[class*="-icon"]').remove();//ui-icon, s-icon
buttons.eq(0).addClass('btn-primary').prepend('<i class="icon-ok"></i>');
buttons.eq(1).prepend('<i class="icon-remove"></i>')
buttons = form.next().find('.navButton a');
buttons.find('.ui-icon').remove();
buttons.eq(0).append('<i class="icon-chevron-left"></i>');
buttons.eq(1).append('<i class="icon-chevron-right"></i>');
}
function style_delete_form(form) {
var buttons = form.next().find('.EditButton .fm-button');
buttons.addClass('btn btn-sm').find('[class*="-icon"]').remove();//ui-icon, s-icon
buttons.eq(0).addClass('btn-danger').prepend('<i class="icon-trash"></i>');
buttons.eq(1).prepend('<i class="icon-remove"></i>')
}
function style_search_filters(form) {
form.find('.delete-rule').val('X');
form.find('.add-rule').addClass('btn btn-xs btn-primary');
form.find('.add-group').addClass('btn btn-xs btn-success');
form.find('.delete-group').addClass('btn btn-xs btn-danger');
}
function style_search_form(form) {
var dialog = form.closest('.ui-jqdialog');
var buttons = dialog.find('.EditTable')
buttons.find('.EditButton a[id*="_reset"]').addClass('btn btn-sm btn-info').find('.ui-icon').attr('class', 'icon-retweet');
buttons.find('.EditButton a[id*="_query"]').addClass('btn btn-sm btn-inverse').find('.ui-icon').attr('class', 'icon-comment-alt');
buttons.find('.EditButton a[id*="_search"]').addClass('btn btn-sm btn-purple').find('.ui-icon').attr('class', 'icon-search');
}
function beforeDeleteCallback(e) {
var form = $(e[0]);
if(form.data('styled')) return false;
form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
style_delete_form(form);
form.data('styled', true);
}
function beforeEditCallback(e) {
var form = $(e[0]);
form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
style_edit_form(form);
}
function updatePagerIcons(table) {
var replacement =
{
'ui-icon-seek-first' : 'icon-double-angle-left bigger-140',
'ui-icon-seek-prev' : 'icon-angle-left bigger-140',
'ui-icon-seek-next' : 'icon-angle-right bigger-140',
'ui-icon-seek-end' : 'icon-double-angle-right bigger-140'
};
$('.ui-pg-table:not(.navtable) > tbody > tr > .ui-pg-button > .ui-icon').each(function(){
var icon = $(this);
var $class = $.trim(icon.attr('class').replace('ui-icon', ''));
if($class in replacement) icon.attr('class', 'ui-icon '+replacement[$class]);
})
}
提前感谢。
=== thanks, resolved with this script ===
$.ajax({
type : 'POST',
url : '<?php echo base_url()."master_data/protected_assets/edit/"?>',
data : 'idasset=<?php echo $idasset;?>',
dataType : 'json',
success : function(retval){
$('#result').html(retval.form_content);
}
})