0

我有一个可编辑的 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

这是来自萤火虫 - 请求正文 Week1=+767%2C077+&Week2=+727%2C055+&Week3=+719%2C411+&Week4=+738%2C102+&Week5=+290%2C921+&Projection=False&DbFieldName=False&hirNode=&FinWor1 =&FinWor2=&FinWor3=&FinWor4=&FinWor5=+3%2C242%2C566+&FinWorP=+2%2C869%2C267+&HealthCareActive=假&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]}}
4

1 回答 1

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

于 2013-04-03T10:16:42.480 回答