【问题标题】:How to refresh the jqgrid automatically?如何自动刷新jqgrid?
【发布时间】:2012-09-05 05:48:21
【问题描述】:

我使用以下脚本将sql数据库中的详细信息绑定到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 是上帝,但当 reloadAfterSubmit 存在时,你在开发者工具的控制台中得到任何错误吗? reloadAfterSubmit 对我来说适用于相同的场景。

标签: javascript jquery jqgrid


【解决方案1】:

你需要触发reloadGrid:-

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

【讨论】:

    猜你喜欢
    • 2013-02-06
    • 2014-12-23
    • 2012-01-20
    • 1970-01-01
    • 2011-10-21
    • 2011-03-09
    • 2020-12-28
    • 2015-11-30
    • 1970-01-01
    相关资源
    最近更新 更多