简体   繁体   English

如何使用自定义按钮发送到JQGrid的editurl?

[英]How do i use a custom button to send to the JQGrid's editurl?

I have the below custom button added to my navigation pager, but i want it to look at what i multi selected and send it to the JQGrid's editurl for processing which is a ASHX.CS page But i can't make sense of the documentation when it comes to custom button 我在导航寻呼机中添加了以下自定义按钮,但是我希望它查看我选择的内容,并将其发送到JQGrid的editurl进行处理,这是ASHX.CS页面,但是当我无法理解文档时,谈到自定义按钮

I can get it call a local function with onClickButton: customButtonClicked but it doesn't send the data like the EDIT button does 我可以用onClickButton调用本地函数:customButtonClicked,但是它不像EDIT按钮那样发送数据

In the end what i want to do it select multiple rows and press a button on the navbar and approve all the selected records 最后,我要执行的操作是选择多行,然后按导航栏上的按钮并批准所有选定的记录

  // add first custom button $('#jQGrid').navButtonAdd('#jQGridPager', { buttonicon: "ui-icon-mail-closed", title: "Send Mail", caption: "Send Mail", position: "last", editData: { WrkId: function () { var sel_id = $('#jQGrid').jqGrid('getGridParam', 'selarrrow'); var value = ""; for (var a = 0; a < sel_id.length; a++) { value = value + $('#jQGrid').jqGrid('getCell', sel_id[a], 'wrkid') + ','; } return value; }, CurrentUser: function () { return '<% =System.Web.HttpContext.Current.User.Identity.Name %>'; } }, afterSubmit: function (response, postdata) { if (response.responseText == "") { $("#jQGrid").trigger("reloadGrid", [{ current: true }]); return [false, response.responseText] } else { $(this).jqGrid('setGridParam', { datatype: 'json' }).trigger('reloadGrid') return [true, response.responseText] } } } ); 

using a few different words (how to manually post data to server json) i was able to find a snippet of an ajax code that made more sense (i'm sure i came across this before but as someone who has no jquery experience i didn't recognize it) 使用几个不同的词(如何手动将数据发布到服务器json),我能够找到更有意义的ajax代码片段(我确定我之前曾遇到过此问题,但作为没有jquery经验的人,我没有无法识别)

but the below sends to the C# handler page the data in a JSON string that was processable, had to use dynamic to read it in but it worked, couldn't get it to not return an error even though there was no error, so i used the complete: instead of success: and then called the trigger to reload the JQGrid 但是以下内容将可处理的JSON字符串中的数据发送到C#处理程序页面,不得不使用dynamic读取它,但是它起作用了,即使没有错误,也无法使它不返回错误,所以我使用complete:而不是成功:然后调用触发器以重新加载JQGrid

Final Code: 最终代码:

$('#jQGrid').navButtonAdd('#jQGridPager',
            {
                buttonicon: "ui-icon-check",
                title: "Approve all selected entries",
                caption: "Approve",
                position: "last",
                onClickButton: function () {
                    var sel_id = $('#jQGrid').jqGrid('getGridParam', 'selarrrow');
                    var value = "";
                    for (var a = 0; a < sel_id.length; a++) {
                        value = value + $('#jQGrid').jqGrid('getCell', sel_id[a], 'wrkid') + ',';
                    };
                    $.ajax({
                        type: "POST",
                        url: "AdministrationHandler.ashx?oper=approve",
                        data: JSON.stringify({
                            WrkId: value,
                            CurrentUser: "<% =System.Web.HttpContext.Current.User.Identity.Name %>"
                        }),
                        dataType: "json",
                        contentType: "application/json; charsset=utf-8",
                        complete: function (xhr, x) {
                            if (xhr.responseText.toUpperCase().indexOf("SUCCESS") >= 0) {
                                alert('Success!\n' + xhr.responseText);
                            }
                            else {
                                alert('Failed!\n' + xhr.responseText + '\n' + x);
                            };
                            $("#jQGrid").jqGrid('setGridParam', { datatype: 'json' }).trigger('reloadGrid');
                        }
                    })
                }
            });

C# Code C#代码

try
{
    String postData = new System.IO.StreamReader(context.Request.InputStream).ReadToEnd();
    var data = JsonConvert.DeserializeObject<dynamic>(postData);
    Approve(data.WrkId.ToString(), data.CurrentUser.ToString());
    strResponse = "Employee records successfully approved";
}
catch
{
    strResponse = "Employee records not approved";
}
context.Response.Write(strResponse);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM