没有调用editURL - JQGrid

时间:2013-04-01 10:17:21

标签: asp.net vb.net jqgrid

我有一个可编辑的jqGrid,使用事件进行内联编辑,但是没有调用EditURL。 编辑数据是vb.net中的Web方法。当我单击一行时,该行变得可编辑,我可以进行更改,但是当我按Enter键时,不会调用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

这是来自萤火虫 - 请求体 Week1 = + 767%2C077 +&安培; Week2 = + 727%2C055 +&安培;译员更加= + 719%2C411 +&安培; Week4 = + 738%2C102 +&安培; Week5 = + 290%2C921 +&安培;投影=假&安培; DbFieldName =假&安培; hirNode =安培; FinWor1 =安培; FinWor2 =安培; FinWor3 =安培; FinWor4 =安培; FinWor5 = + 3%2C242%2C566 +&安培; FinWorP = + 2%2C869%2C267 +&安培; HealthCareActive =假&安培; OPER =编辑和ID = 14

Js Code

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: 'CoulumnPosition', 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 Revenue"," 921,300 "," 899,595 "," 912,983 "," 941,659 "," 805,100 ","RevenueJwo","False","False","False","0","","","","","",""," 4,480,637 "," 5,378,594 ","False",null]}}

1 个答案:

答案 0 :(得分:0)

您需要像添加serializeRowData一样添加serializeGridData回调。以同样的方式添加ajaxRowOptions ajaxGridOptions。选项定义了在编辑行时执行的$.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(function()内注册的不需要的第二个$(document).ready处理程序。我的意思是代码

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函数,因为函数创建了网格。该函数只能被称为一次。如果函数只能调用一次,那么在函数中定义一些代码是什么意思?