2012-12-07 2 views
1

많은 forumns 및 게시물을 검색했으며 아직 편집 유형을 가져올 수 없습니다. editoptions : dataurl을 선택하여 작동합니다.jqgrid Edittype : dataurl에서 값을 저장하지 않음을 선택하십시오.

그리드가 채워지면 데이터로드가 잘로드됩니다. 편집 버튼을 클릭하면 드롭 다운 목록에 올바른 값과 이름이 있습니다. 저장을 클릭하면 매개 변수 중 하나가 누락되었다는 오류가 표시됩니다. 선택한 옵션의 값을 가져 오는 것 같지 않습니다.

포매터 : '선택'옵션을 시도했지만 그리드가로드 될 때 그 열에 아무것도 표시되지 않습니다.

다음은 코드에 대한 내용입니다.

System.InvalidOperationException: Missing parameter: paintID. 
at System.Web.Services.Protocols.ValueCollectionParameterReader.Read(NameValueCollection collection) 
at System.Web.Services.Protocols.HtmlFormParameterReader.Read(HttpRequest request) 
at System.Web.Services.Protocols.HttpServerProtocol.ReadParameters() 
at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest() 

어떤 도움이 크게 감사합니다 :

var buildSelectFromJson = function (data) { 
    var html = '<select>', d = data.d, length = d.length, i = 0, item; 
    for (; i < length; i++) { 
     item = d[i]; 
     html += '<option value=' + item.id + '>' + item.value + '</option>'; 
    } 
    html += '</select>'; 
    return html; 
}; 

$.extend($.jgrid.edit, { 
    ajaxEditOptions: { contentType: "application/json" }, 
    recreateForm: true, 
    serializeEditData: function (postData) { 
     return JSON.stringify(postData); 
    } 
}); 

jQuery("#usage").jqGrid({ 
    url: '/vochaptracker/Services/vochapService.asmx/GetUsage', 
    datatype: 'json', 
    mtype: 'post', 
    loadonce: true, 
    ajaxGridOptions: { contentType: 'application/json; charset=utf-8' }, 
    serializeGridData: function (postData) { 
     return JSON.stringify(postData); 
    }, 
    jsonReader: { 
     root: function (obj) { return obj.d.rows; }, 
     page: function (obj) { return obj.d.page; }, 
     total: function (obj) { return obj.d.total; }, 
     records: function (obj) { return obj.d.records; } 
    }, 
    colNames: ['Date', 'Paint', 'Booth', 'Gallons Used'], 
    colModel: [ 
     { name: 'date', index: 'date', width: 75, editable: true }, 
     { name: 'paint', index: 'paint', width: 300, editable: true, edittype: 'select', formatter:'select', editoptions: { dataUrl: "/vochaptracker/Services/vochapService.asmx/GetPaintsForEdit", 
      buildSelect: buildSelectFromJson} 
     }, 
     { name: 'booth', index: 'booth', width: 100, editable: true, edittype: 'select', formatter:'select', editoptions: { dataUrl: "/vochaptracker/Services/vochapService.asmx/GetBoothsForEdit", 
      buildSelect: buildSelectFromJson}}, 
     { name: 'gallonsUsed', index: 'gallonsUsed', width: 100, editable: true } 
    ], 
    rowNum: 20, 
    rowList: [20, 30, 40], 
    pager: '#pager4', 
    sortname: 'ID', 
    viewrecords: true, 
    sortorder: "desc", 
    caption: "Daily Usage", 
    height: '400', 
    editurl: '/vochaptracker/Services/vochapService.asmx/EditUsage', 
    ajaxSelectOptions: { contentType: "application/json", dataType: 'json', type: "POST" } 
}); 
jQuery("#usage").jqGrid('navGrid', "#pager4", { edit: false, add: false, del: true }); 
jQuery("#usage").jqGrid('inlineNav', "#pager4"); 

웹 서비스 : 내가 편집 한 후 행을 저장하려고하면

public class jqGridPaintHelper 
{ 
    public string total; 
    public string page; 
    public string records; 
    public List<TableRow> rows; 
} 

public class TableRow 
{ 
    public string id; 
    public List<string> cell; 
} 

public class editHelper 
{ 
    public string id; 
    public string value; 
} 

    [WebMethod] 
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)] 
    public jqGridPaintHelper GetUsage(int page, int rows, string sidx, string sord) 
    { 
     vochapdbDataContext db = new vochapdbDataContext(); 
     jqGridPaintHelper helper = new jqGridPaintHelper(); 
     int dbCount = db.DailyUsages.Count(); 
     helper.total = ((dbCount + rows - 1)/rows).ToString(); 
     helper.page = page.ToString(); 
     helper.records = dbCount.ToString(); 

     List<TableRow> usage = new List<TableRow>(dbCount); 
     foreach (DailyUsage row in db.DailyUsages) 
     { 
      usage.Add(new TableRow() 
      { 
       id = row.ID.ToString(), 
       cell = new List<string> { 
        row.date.ToShortDateString(), 
        row.Paint.paintName.ToString(), 
        row.Booth.tag.ToString(), 
        row.gallonsUsed.ToString() 
       } 
      }); 
     } 

     helper.rows = usage; 

     return helper; 
    } 

    [WebMethod] 
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)] 
    public int EditUsage(string ID, string date, string paintID, string boothID, string gallonsUsed, string oper, string id) 
    { 
     vochapdbDataContext db = new vochapdbDataContext(); 

     if (oper == "edit") 
     { 
      db.updateUsage(int.Parse(ID), DateTime.Parse(date), paintID, int.Parse(boothID), decimal.Parse(gallonsUsed)); 
     } 
     else if (oper == "add") 
     { 
      DailyUsage newUsage = new DailyUsage(); 
      newUsage.date = DateTime.Parse(date); 
      newUsage.paintID = paintID; 
      newUsage.boothID = int.Parse(paintID); 
      newUsage.gallonsUsed = decimal.Parse(gallonsUsed); 

      db.DailyUsages.InsertOnSubmit(newUsage); 
      db.SubmitChanges(); 
     } 
     else if (oper == "del") 
     { 
      db.deleteUsage(int.Parse(id)); 
     } 

     return 1; 
    } 

    [WebMethod] 
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)] 
    public List<editHelper> GetPaintsForEdit() 
    { 
     vochapdbDataContext db = new vochapdbDataContext(); 

     List<editHelper> paints = new List<editHelper>(); 

     foreach (Paint row in db.Paints) 
     { 
      paints.Add(new editHelper() { id = row.ID, value = row.paintName }); 
     } 

     return paints; 
    } 

    [WebMethod] 
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)] 
    public List<editHelper> GetBoothsForEdit() 
    { 
     vochapdbDataContext db = new vochapdbDataContext(); 

     List<editHelper> booths = new List<editHelper>(); 

     foreach (Booth row in db.Booths) 
     { 
      booths.Add(new editHelper() { id = row.ID.ToString(), value = row.tag }); 
     } 

     return booths; 
    } 

이것은 내가 얻을 오류입니다. 나는 약 한 달 동안 붙어 있었다.

답변

1

나는 그것을 마침내 발견했습니다. 내 드롭 다운 선택 목록에 이상한 값이 있습니다.

나는 값 주위에 "추가하고이 문제를 해결

올드 :.

html += '<option value=' + item.id + '>' + item.value + '</option>'; 

새로운 기능 :

html += '<option value="' + item.id + '">' + item.value + '</option>';