【问题标题】:editURL not being called - JQGrid没有调用editURL - JQGrid
【发布时间】:2013-04-01 10:17:20
【问题描述】:

我有一个可编辑的 jqGrid,内联编辑事件,但没有调用 EditURL。

编辑数据是 vb.net 中的一种网络方法。当我单击一行时,该行变为可编辑并且我可以进行更改,但是当我点击输入时,EditURL 没有被调用。请提出任何必要的更改。

<ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _
<WebMethod()> _
Public Shared Function LoadData() As jqGridResult

    'If MuList.SelectedValue <> "0" AndAlso MuList.SelectedValue <> String.Empty Then
    '    hirNodeMu = hirNodeMu.Parse(MuList.SelectedValue)
    'Else
    '    hirNodeMu = 0
    'End If

    'Dim hirNode As Integer = hirNodeMu
    'If hirNode = 0 Then
    '    hirNode = hirNodeCurrent
    'End If

    Dim sidx As String = ""
    Dim sord As String = "asc"
    Dim page As Integer = 1
    Dim rows As Integer = 1000

    Dim entryFieldsOnly As Integer = 1

    Dim hirNode As Integer = 5
    Dim fiscalYear As Integer = 2012
    Dim fiscalPeriod As Integer = 3

    Dim dtWORData As DataTable = New DataTable()

    Dim ConnectString As String = ConfigurationSettings.AppSettings("DbConnection")

    Using sqlConnection As New SqlConnection(ConnectString)

        Dim Conn As SqlConnection = New SqlConnection(ConnectString)
        Dim Cmd As SqlCommand = New SqlCommand("finWorFactView", Conn)
        Cmd.CommandType = CommandType.StoredProcedure
        Cmd.Parameters.Add("@hirNodeBase", SqlDbType.Int, 4).Value = hirNode
        Cmd.Parameters.Add("@FiscalYear", SqlDbType.Int, 4).Value = fiscalYear
        Cmd.Parameters.Add("@FiscalPeriod", SqlDbType.Int, 4).Value = fiscalPeriod
        Cmd.Parameters.Add("@EntryFieldsOnly", SqlDbType.Int, 4).Value = entryFieldsOnly
        Conn.Open()

        Dim DA As SqlDataAdapter = New SqlDataAdapter(Cmd)

        DA.Fill(dtWORData)

    End Using

    Dim pageIndex As Integer = page
    Dim pageSize As Integer = rows
    Dim startRow As Integer = (pageIndex * pageSize) + 1
    Dim totalRecords As Integer = dtWORData.Rows.Count()
    Dim totalPages As Integer = CInt(Math.Ceiling(CSng(totalRecords) / CSng(pageSize)))

    Dim row As List(Of jqGridRows) = New List(Of jqGridRows)

    For i As Integer = 0 To dtWORData.Rows.Count - 1

        Dim newRow As jqGridRows = New jqGridRows

        newRow.id = Convert.ToInt32(dtWORData.Rows(i)("DisplayOrder"))

        newRow.cell(0) = dtWORData.Rows(i)("DisplayOrder").ToString()
        newRow.cell(1) = dtWORData.Rows(i)("ColumnPosition").ToString()
        newRow.cell(2) = dtWORData.Rows(i)("ColumnName").ToString()
        newRow.cell(3) = dtWORData.Rows(i)("Week1").ToString()
        newRow.cell(4) = dtWORData.Rows(i)("Week2").ToString()
        newRow.cell(5) = dtWORData.Rows(i)("Week3").ToString()
        newRow.cell(6) = dtWORData.Rows(i)("Week4").ToString()
        newRow.cell(7) = dtWORData.Rows(i)("Week5").ToString()
        newRow.cell(8) = dtWORData.Rows(i)("DbFieldName").ToString()
        newRow.cell(9) = dtWORData.Rows(i)("Updateable").ToString()
        newRow.cell(10) = dtWORData.Rows(i)("PayrollActive").ToString()
        newRow.cell(11) = dtWORData.Rows(i)("PurchasingActive").ToString()
        newRow.cell(12) = dtWORData.Rows(i)("hirNode").ToString()
        newRow.cell(13) = dtWORData.Rows(i)("finWor1").ToString()
        newRow.cell(14) = dtWORData.Rows(i)("finWor2").ToString()
        newRow.cell(15) = dtWORData.Rows(i)("finWor3").ToString()
        newRow.cell(16) = dtWORData.Rows(i)("finWor4").ToString()
        newRow.cell(17) = dtWORData.Rows(i)("finWor5").ToString()
        newRow.cell(18) = dtWORData.Rows(i)("finWorP").ToString()
        newRow.cell(19) = dtWORData.Rows(i)("Total").ToString()
        newRow.cell(20) = dtWORData.Rows(i)("Projection").ToString()
        newRow.cell(21) = dtWORData.Rows(i)("HealthCareActive").ToString()

        row.Add(newRow)
    Next

    Dim result As jqGridResult = New jqGridResult

    result.total = totalPages
    result.page = page
    result.records = totalRecords
    result.rows = row

    Return result

End Function

<ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _
<WebMethod()> _
Public Shared Function EditData(ByVal Week1 As String, ByVal Week2 As String, ByVal Week3 As String, ByVal Week4 As String, _
                                ByVal Week5 As String, ByVal Projection As String, _
                                ByVal DbFieldName As String, ByVal hirNode As String, _
                                ByVal FinWor1 As String, ByVal FinWor2 As String, ByVal FinWor3 As String, ByVal FinWor4 As String, _
                                ByVal FinWor5 As String, ByVal FinWorP As String, ByVal HealthCareActive As String, _
                                ByVal oper As String, ByVal id As String) As Boolean

    Dim objClass As New _Default
    objClass.LogError(Week1 + " " + Week2 + " " + Week3 + " " + Week4 + " " + Week5 + " " + Projection)

    Return True

End Function

这是来自 firebug - 请求正文 Week1=+767%2C077+&Week2=+727%2C055+&Week3=+719%2C411+&Week4=+738%2C102+&Week5=+290%2C921+&Projection=False&DbFieldName=False&hirNode=&FinWor1=&FinWor2=&FinWor3=&FinWor4=&FinWor =+3%2C242%2C566+&FinWorP=+2%2C869%2C267+&HealthCareActive=False&oper=edit&id=14

JS代码

jQuery(document).ready(function($) {

var lastsel;

$(document).ready(function() {


    loadGrid();
});

function loadGrid() {
    jQuery("#tblWOR").jqGrid({
        url: 'Default.aspx/LoadData',
        mtype: 'POST',
        datatype: 'json',
        ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
        serializeGridData: function(postData) {
            return JSON.stringify(postData);
        },
        rowNum: 1000,
        width: 1200,
        height: 'auto',
        colNames: ['Display Order', 'Column P', 'Column N', 'Week1(1-7)', 'Week2(8-14)', 'Week2(15-21)', 'Week1(22-28)', 'Week1(29-31)',
                    'Total Month' + '</br>' + 'to Date', 'Projection' + '</br>' + 'for Month',
                    'DbFieldName', 'Updateable', 'PayrollActive', 'PurchasingActive', 'hirNode',
                    'WOR1', 'WOR2', 'WOR3', 'WOR4', 'WOR5', 'WORP', 'HealthCareActive',
                ],
        colModel: [
                { name: 'DisplayOrder', index: 'DisplayOrder', hidden: true },
                { name: 'ColumnPosition', index: 'Week1', width: 55 },
                { name: 'ColumnName', index: 'Week1', width: 80 },
                { name: 'Week1', index: 'Week1', width: 55, editable: true, edittype: 'text' },
                { name: 'Week2', index: 'Week2', width: 55, editable: false, edittype: 'text' },
                { name: 'Week3', index: 'Week3', width: 55, editable: false, edittype: 'text' },
                { name: 'Week4', index: 'Week4', width: 55, editable: false, edittype: 'text' },
                { name: 'Week5', index: 'Week5', width: 55, editable: false, edittype: 'text' },
                { name: 'Total', index: 'Total', width: 55 },
                { name: 'Projection', index: 'Projection', width: 55, editable: false, edittype: 'text' },
                { name: 'DbFieldName', index: 'DbFieldName', editable: false, hidden: true },
                { name: 'Updateable', index: 'Updateable', editable: false, hidden: true },
                { name: 'PayrollActive', index: 'PayrollActive', editable: false, hidden: true },
                { name: 'PurchasingActive', index: 'PurchasingActive', editable: false, hidden: true },
                { name: 'hirNode', index: 'hirNode', editable: false, hidden: true },
                { name: 'FinWor1', index: 'FinWor1', editable: false, hidden: true },
                { name: 'FinWor2', index: 'FinWor2', editable: false, hidden: true },
                { name: 'FinWor3', index: 'FinWor3', editable: false, hidden: true },
                { name: 'FinWor4', index: 'FinWor4', editable: false, hidden: true },
                { name: 'FinWor5', index: 'FinWor5', editable: false, hidden: true },
                { name: 'FinWorP', index: 'FinWorP', editable: false, hidden: true },
                { name: 'HealthCareActive', index: 'HealthCareActive', editable: false, hidden: true }
                ],
        pager: '#divWOR',
        jsonReader: {
            root: "d.rows",
            page: "d.page",
            total: "d.total",
            records: "d.records",
            repeatitems: false
        },
        sortname: 'DisplayOrder',
        viewrecords: true,
        sortorder: "asc",
        onSelectRow: function(DisplayOrder) {
            if (DisplayOrder && DisplayOrder !== lastsel) {
                jQuery('#tblWOR').jqGrid('restoreRow', lastsel);
                jQuery('#tblWOR').jqGrid('editRow', DisplayOrder, true);
                lastsel = DisplayOrder;
            }
        },
        cellsubmit: 'remote',
        editurl: "Default.aspx/EditData",
        caption: "WOR View Grid"           
    });
    jQuery("#tblWOR").jqGrid('navGrid', "#divWOR", { edit: false, add: false, del: false });
}

});

我能够调试我的代码。数据正在通过 web 方法返回,但未显示在网格中。

这是我得到的数据..(我只显示一行,因为数据很大)

{"d":{"__type":"LearnEveryday._Default+jqGridResult","total":1,"page":1,"records":25,"rows":[{"id":3,"cell ":["3","2","JWO 收入","921,300","899,595","912,983","941,659","805,100","RevenueJwo","False","False","False ","0","","","","","",""," 4,480,637 "," 5,378,594 ","False",null]}}

【问题讨论】:

  • 您发布的代码中有很多小错误。 datatype 作为函数的使用也很糟糕,而且您的服务器代码也有一定的错误(有关更多信息,请参阅the answer)。对于您的主要问题:您写了“未调用 EditURL”。你是怎么验证的?您是否使用 Fiddler、Firebug、IE 的开发者工具或其他工具来捕获 HTTP 流量?你能看到没有调用保存你刚刚在方法“Default.aspx/EditData”中设置断点的行吗? EditData 方法的签名(哪些参数)是什么?
  • 如果您在本地化错误时遇到问题,您可以使用LoadDataEditData 的代码附加您的问题,来自Default.aspx
  • 嗨,我正在检查断点。我刚刚签入了 Firebug,它被调用了。当我使用 LoadData 时,我能够调试 vb 代码,所以我认为这一次它也会遇到断点。
  • 如果您正确定义了EditData,那么EditData 将被调用,您将能够看到断点命中。所以我认为,错误在于您没有发布的 服务器代码
  • 刚刚更新了vb代码。请看一下。谢谢!

标签: asp.net vb.net jqgrid


【解决方案1】:

您需要像添加serializeGridData 一样添加serializeRowData 回调。同样,您需要添加ajaxRowOptions,它看起来像ajaxGridOptions。 options 定义了在编辑行期间执行的$.ajax 选项:

ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
ajaxRowOptions: { contentType: 'application/json; charset=utf-8' },
serializeGridData: function (postData) {
    return JSON.stringify(postData);
},
serializeRowData: function (postData) {
    return JSON.stringify(postData);
}

您应该删除在$(document).ready 中注册的不需要的第二个$(document).ready(function() 处理程序。我的意思是代码

jQuery(document).ready(function($) {

    var lastsel;

    $(document).ready(function() {
        loadGrid();
    });

    function loadGrid() {
        jQuery("#tblWOR").jqGrid({
            ...
        });
        jQuery("#tblWOR").jqGrid('navGrid', "#divWOR", { edit: false, add: false, del: false });
    }
});

应该换成

jQuery(document).ready(function($) {
    var lastsel;
    $("#tblWOR").jqGrid({
        ...
    }).jqGrid('navGrid', "#divWOR", { edit: false, add: false, del: false });
});

我还删除了loadGrid 函数,因为函数创建 网格。该函数只能调用一次。如果函数只能调用一次,那么在函数中定义一些代码是什么意思?

【讨论】:

  • 它的工作!!!!非常感谢.. 我将编辑我的帖子以包含旧代码和新代码
  • @Arshya:不客气!如果问题解决了,您应该"accept" 回答。顺便说一句,您现在真的在jsonReader 中使用repeatitems: false 选项吗?您的服务器代码看起来像您以另一种格式生成数据。此外,我写信给您添加gridview: true 以提高性能。该选项应该是所有网格中的标准选项。我还给你写了关于在回调中使用$(this) 而不是jQuery('#tblWOR')
  • @Arshya:cellsubmit: 'remote' 选项仅在使用单元格编辑的情况下使用。您使用内联编辑。因此,您可以删除该选项。我也想知道为什么你在网格中有这么多隐藏的列。看来我不需要了。通常一个需要只有id 的行。服务器上已经存在所有其他信息。无需将信息发送给客户并返回。不是吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-11
相关资源
最近更新 更多