【问题标题】:unable to display success message after editing the row in jqgrid在 jqgrid 中编辑行后无法显示成功消息
【发布时间】:2015-01-01 11:25:42
【问题描述】:

我正在使用引导程序开发基于 Web 的应用程序。 我正在尝试在页面加载时在我的网格中实现内联编辑,但在执行编辑功能后显示成功或失败消息时遇到了一些问题。

这是我的代码:

  $(document).ready(function () {
    var GetUrl = Web_Path + '/Test/TestHandler/GetTestData/' + AjaxHandlerName;

                jQuery("#jqGrid-container").jqGrid({
                    url: GetUrl,
                    datatype: 'json',
                    mtype: 'POST',
                    postData: { SearchInfo: function () { return getSearchPostData() } },
                    colNames: [' ', 'ID', 'Name', 'ContactNo', 'EmpId', 'MailId', 'RoleName'],
                    colModel: [
                    { name: 'myac', index: '', width: 80, fixed: true, sortable: false, resize: false,
                        formatter: 'actions',
                        formatoptions: {
                            keys: true,
                            delOptions: { recreateForm: true, beforeShowForm: beforeDeleteCallback }
                        }
                    },
                                { name: 'Id', index: 'Id', hidden: true, editable: true },
                                { name: 'Name', index: 'Name', validation: { required: true }, sortable: true, editable: true, editoptions: { size: "40", maxlength: "50"} },
                                { name: 'ContactNo', index: 'ContactNo', sortable: false, editable: true, editoptions: { size: "20", maxlength: "30"} },
                                { name: 'EmpId', index: 'EmpId', sortable: false, editable: true, editoptions: { size: "20", maxlength: "30"} },
                                { name: 'MailId', index: 'MailId', sortable: false, editable: true, editoptions: { size: "40", maxlength: "50"} },
 {name: 'RoleName', index: 'RoleName', sortable: false }
  ],


                    editurl: ISM_Web_Path + '/Test/TestHandler/UpdateTestContacts/' + ISMAjaxHandlerName,                 

                    ajaxRowOptions: {
                    afterEditRow: function (rowid, cellname, value, iRow, iCol) {
                    alert('success');
                    }
                    },                 
                    serializeRowData: function (postdata) {
                    return { ContactInfo: JSON.stringify(postdata) };                     
                    },
                    jsonReader: {
                        id: 'Id',
                        repeatitems: false
                    },
                    height: "100%",
                    pager: '#jqGrid-pager',
                    rowNum: 10,
                    rowList: [10, 20, 30],
                    sortname: 'Id',
                    sortorder: 'desc',
                    viewrecords: true,
                    caption: "JQ grid data",
                    loadComplete: function () {
                        var table = this;
                        updatePagerIcons(table);                       
                    }
                });
});

 function getSearchPostData() {
            var searchData = {};
            searchData.Id=1;

            return JSON.stringify(searchData);
        }
 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]);
            })
}

 <div class="row">
        <div class="col-xs-12">           
            <table id="jqGrid-container" class="ui-jqgrid ui-widget ui-widget-content ui-corner-all">
            </table>
            <div id="jqGrid-pager">
            </div>           
        </div>
    </div>

处理函数

 public void UpdateTestContacts(HttpContext context)
        {
            TestContact contactInfo =new TestContact();
            string jsonData = context.Request.Params["ContactInfo"];
            MemoryStream TestContactMs = new MemoryStream(Encoding.UTF8.GetBytes(jsonData));
            DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(TestContact));
            contactInfo = (RelationshipContact)serializer.ReadObject(TestContactMs );              
            //call manger function
            // return true or false
        }

TestContact.cs

 public class TestContact
    {
        public int Id { get; set; }

        public string Name { get; set; }

        public string ContactNo { get; set; }

        public string EmpId { get; set; }

        public int RelId { get; set; }

        public int TypeId { get; set; }

        public string MailId { get; set; }

        public string RoleName { get; set; }       
    }

我用过jquery.jqGrid.min.js

成功编辑行后,我无法显示成功消息。 我用过 afterEditRow 请帮帮我。

【问题讨论】:

    标签: javascript jquery twitter-bootstrap jqgrid


    【解决方案1】:

    ajaxRowOptions 内部没有afterEditRow 回调函数。推荐使用aftersavefunc内联编辑的回调函数,可以指定为formatoptionsafterSave函数:

    formatter: 'actions',
    formatoptions: {
        keys: true,
        afterSave: function (rowid, response, postdata, options) {
            alert("success");
        },
        delOptions: { recreateForm: true, beforeShowForm: beforeDeleteCallback }
    }
    

    【讨论】:

      【解决方案2】:
       ajaxRowOptions: {
                        success: function (data, textStatus) {
                          if(textStatus=="true")
                          {
                          alert('success');
                          }
                          else
                          {
                          alert('failure');
                          }
                        }
       }
      

      我在处理程序中返回 true。 上面的代码对我有用。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-10-11
        • 2012-06-22
        • 2017-01-29
        • 1970-01-01
        • 2015-03-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多